passing listbox selection to a query (1 Viewer)

JimL

Registered User.
Local time
Today, 12:33
Joined
Jul 9, 2019
Messages
20
I have created a listbox named CenterCombo which contains a field called 'LocationName1'.

I have used the following criterion in a query containing the field LocationName1: [Forms]![Center Level]![LocationName1]

Unfortunately, the query returns only the records associated with the first name in the listbox regardless of whatever field is selected.

Have I missed anything in the construction of the criterion?

Any and all help is greatly appreciated!

Thanks and Regards

JimL
 

isladogs

MVP / VIP
Local time
Today, 17:33
Joined
Jan 14, 2017
Messages
18,209
Use the control name CenterCombo in the query criteria instead of the field name
 

JimL

Registered User.
Local time
Today, 12:33
Joined
Jul 9, 2019
Messages
20
Thanks so much, Isladogs! The solution works.

I am faced with the fact that the criterion passed to the query appears to remain in memory even though I have added a refresh command before the openquery command. The form needs to be closed and re-opened before a new listbox entry can be passed.

Again, much appreciated.

Regards

JimL
 

isladogs

MVP / VIP
Local time
Today, 17:33
Joined
Jan 14, 2017
Messages
18,209
There should be no need to close and reopen the form.
What code are you using?
 

June7

AWF VIP
Local time
Today, 08:33
Joined
Mar 9, 2014
Messages
5,464
This is actually a combobox, not a listbox?
 

JimL

Registered User.
Local time
Today, 12:33
Joined
Jul 9, 2019
Messages
20
I am using the macro builder behind the button. The first action is refresh and the second action is to run the query.

Thanks
 

isladogs

MVP / VIP
Local time
Today, 17:33
Joined
Jan 14, 2017
Messages
18,209
I am using the macro builder behind the button. The first action is refresh and the second action is to run the query.

I never use macros so can only offer general comments.
Perhaps I'm being dense but I'm not sure why you are refreshing before running the query.
Try requerying (or possibly refreshing) after the query.
 

Users who are viewing this thread

Top Bottom