Combo Box Selection

  • Thread starter Thread starter George
  • Start date Start date
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
 
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)
 
Back
Top