Filter text box

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
 
A

Allen Browne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top