Filter text box

  • Thread starter Thread starter Glenn Brown
  • Start date Start date
G

Glenn Brown

I want to have a filter that searches from two fields in
a form. The filter criteria will be entered into a simple
text box.

Any help would be appreciated.

Glenn
 
This example assumes fields named Surname and Firstname, and the unbound
search box named txtFindName:

Private Sub txtFindName_AfterUpdate()
Dim strWhere As String
If Not IsNull(Me.txtFindName) Then
strWhere = "([Surname] = """ & Me.txtFindName & _
""") OR ([Firstname] = """ & Me.txtFindName & """)"
Debug.Print strWhere
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub

The extra quote marks are only required if the fields are Text type.

Remove the "Debug.Print..." line once you have it working.
 
Back
Top