Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference combo box column in query?

Status
Not open for further replies.

ssvec

Technical User
Jun 12, 2001
15
US
OK I give up. I have a main form with a combo box that has 2 columns in it. The first field is hidden and is a number that is used to reference other tables. The second field is a name that the user selects. When the user clicks on a print button, a report that is based on a query runs, the query has fields from a second table I'll call 'Second'. I want the query to look at the combo box on the main form, get the index value from the hidden first column in the combo box, and return only those items from the second table that have a matching index number.

I've tried the following sql:
SELECT Second.ID, Second.Name, Second.Gender
FROM Second
where ID =Forms!MainForm!ComboBox.Column(0);

but I get an error that there is an undefined function.

 
Looks like it's time for a little work-around....

Add an invisible text box to your form (i.e txtTemp). In your combo box's On Change event, put code like this:
Code:
Me.txtTemp = Forms!MainForm!ComboBox.Column(0)
Change the criteria of your query to be the invisible text box on your form:
Code:
......
where ID =Forms!MainForm!txtTemp;
 
Thanks! Elegantly simple but totally effective.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top