Avatar of wileedingo
wileedingo
 asked on

using list box column for query criteria

Hello,

I have a 4-column list box.  I am trying to create a select query that will use the contents of two columns in the list box as criteria.

For now the list box is called List0 and is on a form called frmMakeModelFix1.  The SQL statement I have tried is:

SELECT CabinetRecords.Manufacturer, CabinetRecords.Model, CabinetRecords.Type, CabinetRecords.Size, CabinetRecords.In_Use
FROM CabinetRecords
WHERE (((CabinetRecords.Manufacturer)=[Forms]![frmMakeModelFix1]![List0].Column(0)));

It is supposed to select the records from the table CabinetRecords where the Manufacturer is the same as the Manufacturer
in the selected list box record. Once it works, I will add criteria to further specify that the Model must be the same as that in the
selected list box record.

It doesn't work and gives me the message: "Undefined function '[Forms]![frmMakeModelFix1]![List0].Column' in expression"

It works with the bound column when you don't need to specify the column, just the list name.

Will what I'm trying to do work?

wileedingo.
Microsoft Access

Avatar of undefined
Last Comment
wileedingo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
dathmagar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
heer2351

You can not reference a column in a query, but you can reference a control that is why dathmagar solution will work.

The other way to do this is to create the row source of the list box in the after update event of the combobox dynamically:

private sub List0_afterUpdate()

  me!List0.rowsource = "SELECT Manufacturer, Model, Type, Size, In_Use FROM CabinetRecords WHERE Manufacturer = " & me![List0].Column(0)
end sub

So you are appending the value of the column in the listbox instead of putting it in the string.
wileedingo

ASKER
Thank you dathmagar and heer2351 for the further explanation.

I had noticed that I could reference the column from a text box as was required for the solution - and for that reason I felt
 certain that I could reference the column as criteria in a query. I just thought I was doing it wrong.

thanks again.

wileedingo
Your help has saved me hundreds of hours of internet surfing.
fblack61