Filtering

A

Anthony

I am trying to use a textbox to filter a form. I want it to be able to filter each time I type a letter. For example, if I had a table of states, when 'c' is typed in to the textbox, all states that begins with the letter 'c' would show up. When I type in 'a' after the 'c', which makes the input "ca", then only "California" would show up. Anyone knows how to do that in both Access 97 and Access 2000?

Thanks a million in advance.
 
M

Marshall Barton

Anthony said:
I am trying to use a textbox to filter a form. I want it to be able to filter each time I type a letter. For example, if I had a table of states, when 'c' is typed in to the textbox, all states that begins with the letter 'c' would show up. When I type in 'a' after the 'c', which makes the input "ca", then only "California" would show up. Anyone knows how to do that in both Access 97 and Access 2000?


Place the unbound text box in the form's header section.
Use code like the following in the text box's AfterUpdate
event procedure:

Me.Filter = "statefield LIKE ""*" & Me.thetextbox & """"
Me.FilterOn = True

If your form is more than a simple form, then it may be more
reliable to reset the form's record source instead of using
the less than perfect Filter property:

Me.RecordSource = "SELECT statefield FROM statestable " _
& "WHERE statefield LIKE ""*" & Me.thetextbox & """"
 

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