Combo Box Selection

G

George

My Combo Box has two colunms - Rank and Last Name.

In my query criteria how do I point to each column in the Combo Box, I tried
this, doesn't work.

[Forms]![F-Main_Menu]![Combo0].[ColumnCount]="2"

Thanks
 
K

Ken Snell \(MVP\)

The Column property of a combobox or listbox lets you read the value of
columns that are not the Bound Column. However, you cannot read that
property directly in a query -- instead, you need to use a VBA function that
reads and returns it to your query.

Create the following function in a regular module:

Public Function ReadComboListBoxColumn( _
strFormName As String, strControlName As String, _
intColumnNumber As Integer) As Variant
' NOTE: intColumnNumber is a "zero-based" number, meaning that you
' must provide 0 to read the first column, 1 to read the second
' column, etc.
ReadComboListBoxColumn = _
Forms(strFormName).Controls(strControlName).Column(intColumnNumber)
End Function


Then use this function in your query:

SELECT Field1, Field2
FROM TableName
WHERE Field2 = ReadComboListBoxColumn("FormName", "ComboboxName", 1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top