Filter a form when typing in a text box

SteveL13
SteveL13 used Ask the Experts™
on
I'm trying to filer records being displayed in a form when the user types in a text box.  This what I have in the onchange event of the form but if I try to type "123" as an example, it replaces the "1" with a "2" when I type the "2".

I also want it to display ALL records that contain "123" in the street address.


    Me.Filter = "StreetAddress like '" & Me.txtFindStreetAddress.Text & "*'"
    Me.FilterOn = True
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Commented:
use the onchange event..read your input and filter your data with LIKE

Author

Commented:
I don't understand.  I am using the onchange event but it isn't working as I stated.
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
OK, so you should be using the textbox OnChange event,

Where is the txtFindStreetAddress control located on your form (header)?  If not that is where it should be.

Private Sub  txtFindStreetAddress_Change

     Me.Filter = "StreetAddress like '*" & Me.txtFindStreetAddress.Text & "*'"
     Me.FilterOn = True 

End Sub

Open in new window

But doing this in the ChangeEvent of a textbox can be very demanding on the database, as the form will be filtered after every key stroke and depending on the size of the dataset, this could be rather annoying.  Instead, I would use a button next to the textbox, and actually modify the SQL for the form when the button is clicked.  This way, the form isn't constantly trying to get refiltered.  Furthermore, it will limit the demand on the network, by only returning rows to the recordset which meet your entered text string.

Author

Commented:
I went with a command button per you suggestion.  Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial