Access VBA Filter ComboBox

Murray Brown
Murray Brown used Ask the Experts™
on
Hi
I want to filter a ComboBox by the letters in an adjacent text box as the user types.
What is the best way to do this and what code would I use if my controls are called
ComboBox1 and TextBox1?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
President / Owner CARDA Consultants Inc.
Distinguished Expert 2018
Commented:
There are a number of ways to accomplish this, but here is one.

Create an On Change event for the textbox
Private Sub TextBox1_Change()
    Me.ComboBox1.Requery
End Sub

Open in new window


Now for the combo box, you need to setup the Row Source so it uses the textbox to filter the given field by using a criteria such as
Like "*" & [forms]![YourFormName]![TextBox1].[Text] & "*"

Open in new window

which in turn actually generates a WHERE clause like:
WHERE (((YourTableName.YourFieldName) Like "*" & [forms]![YourFormName]![TextBox1].[Text] & "*"))

Open in new window

Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
thanks very much
Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

Commented:
My pleasure Murray, always glad to help.

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