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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference a ComboBox Column in a Query 1

Status
Not open for further replies.

BlakeK

Programmer
Oct 1, 2001
59
US
If I want to reference the bound column of a combo box in the criteria of a query, I put the following in the criteria:
[Forms]![form_name]![cbx_name]

Now what if I want to refernce another column of that Combo Box?

I put the following:
[Forms]![form_name]![cbx_name].Column(2)

This is how I would reference it in VBA, but trying to put that in a query results in an error:
"Undefined funtion '[Forms]![form_name]![cbx_name].Column' in expression"

Help! Thanks. :)
 
You may use an hidden textbox in your form and update it with the Column value just before launching the query.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yeah, I thought about that, but it's a hack.
Does that mean there is not proper way to access that data directly in a query?

Thanks. :)
 
Another way is to write your own function to grab the column value, something like this:
Public Function getComboCol(strForm, strCombo, intCol)
getComboCol = Forms(strForm)(strCombo).Column(intCol)
End Function
And in the criteria you put this:
=getComboCol("form_name","cbx_name",2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You can use something like:
=Eval("[Forms]![form_name]![cbx_name].Column(2)")

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
How are ya BlakeK . . . . .

The problem is that the [blue]Column Property[/blue] is only available to a [blue]Macro[/blue] or [blue]VBA[/blue] at runtime. Not as criteria in query. This is the reason for the error!

With that, [blue]PHV's[/blue] function call is the way to go. . . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top