Filter ListBox with ComboBox?!

dejanc

Registered User.
Local time
Today, 15:03
Joined
Aug 4, 2009
Messages
45
Hello all,
I need to have a comboBox which will filter listBox. I have create a query, relationship, and put AfterUpdate VB code on comboBox. But wont work, and listbox getting a blank values...?!

I have attached an example....

Thanks anyone in advance for help....!!!
 

Attachments

You need to rename the objects in the code to match the objects in your database.

Helpful developers often use dummy names like "yourtable", "yourform" and "listbox" as examples.
Change these to your object names and the code will probably work
 
First, thanks for help GalaxiomAtHom
sorry, I have send wrong zip file.
here is a new one.

Can you please check this one?
 

Attachments

The code had two problems.

You had WHERE [tblCity].[City] but FROM [tblPerson]

When testing a field against a value, that value must be in quote marks.
Notice how the single quotes are included in the WHERE clause.

Code:
 ListFilter = "SELECT [tblPerson].[surname] " & _
"FROM tblPerson " & _
"WHERE [tblPerson].[city] = '" & Me.cboCity.Value & "'"

Alternatively instead of using the value in quotes you can simply enter the full name of the control:

WHERE [tblPerson].[city] = Forms!Form1.cboCity

(Since Value is the default property of a combobox it can be omitted.)
 

Users who are viewing this thread

Back
Top Bottom