I've searched this forum (and many others) and although I can find many posts related to filtering subforms, I can really find anything that works for my specific situation. It may be a really simple fix, but here it is:
I have a main form (frmPeople) that has an unbound textbox and an unbound subform (sfrmPeopleSearch) that displays all the fields and records in a table. What i'd like to do is filter the subform based on the data entered into the textbox. I'd like for the filter to include all fields, not just a single field (let's assume there are two fields - Name and Address).
Here is the code i found on the web but I can't get it to work. I don't get any error, but simply nothing happens when I enter data into the textbox:
Any ideas? Thanks in advance for your help!
I have a main form (frmPeople) that has an unbound textbox and an unbound subform (sfrmPeopleSearch) that displays all the fields and records in a table. What i'd like to do is filter the subform based on the data entered into the textbox. I'd like for the filter to include all fields, not just a single field (let's assume there are two fields - Name and Address).
Here is the code i found on the web but I can't get it to work. I don't get any error, but simply nothing happens when I enter data into the textbox:
Code:
Private Sub txtSearch_AfterUpdate()
Dim strWhere As String
strWhere = ""
If Not IsNull(Me.txtSearch) Then
strWhere = strWhere & " ([EmployeeName] like '*" & Me.txtSearch & "*' OR "
strWhere = strWhere & " [EmployeeAddress] like '*" & Me.txtSearch & "*') AND "
End If
'remove final AND
If strWhere <> "" Then
strWhere = Left(strWhere, Len(strWhere) - 5)
Forms!frmPeople.sfrmPeopleSearch.Form.Filter = strWhere
Forms!frmPeople.sfrmPeopleSearch.Form.FilterOn = True
Else
strWhere = "1=1" 'this is always true and forces the filter to clear
Forms!frmPeople.sfrmPeopleSearch.Form.Filter = strWhere
Forms!frmPeople.sfrmPeopleSearch.Form.FilterOn = True
End If
End Sub
Any ideas? Thanks in advance for your help!
Last edited: