Dynamically filter a list box by text box entry

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a text box and list box, and I'm trying to filter the
contents of the list box (reference to a table using 'SELECT ... Like
<textbox> & '*').

It works, but only once the user has entered info into the textbox and then
left the text box. I want the list box to refilter as the user types into the
text box.

I have tried a KeyUp event where the code refocuses the cursor. It works in
terms of updating the listbox, but on returning to the textbox it highlights
the contents and so the second keystroke overwrites the first.

All help very much appreciated.
 
If your ListBox is called lstList and your text box is called txtFilter then
change your SELECT statement in your list box to this

SELECT [TableName].[FieldName] FROM [TableName] WHERE [FieldName] LIKE
txtFilter.Text & "*";

In the On Change event of the txtFilter box put this

lstList.Requery
 
Back
Top