It depends. Generally the combo box will take the PK of the record you are searching for in the combo box. This can be problematic if you are limited to unique values and you only want to return one record.
You can either pass the PK of the record found in the combo box, the value appearing in the combo box, or any of the values in any of the columns in your look up query.
You can also have the query that your form or report is built on look for the combo box on the form you are searching from by adding a statement to the query iteself like this:
[Forms]![frmMyForm].[cboMyComboBox]
So when the query opens, it will just look for whatever is in your combo box at the time, no need to pass the value in a SQL statement.
Here is how you pass an integer:
Dim inComboValue As Integer
Dim stLink As String
inComboValue = Me.MyComboBox
stLink = "[MyIntegerField] = " & inComboValue
Here is how you pass a string:
Dim stComboValue As String
Dim stLink As String
stComboValue = Me.MyComboBox
stLink = "[MyStringField] = " & "'" & stComboValue & "'"
You may also wish to check for IsNull or "" in the combo box so that your code does not through an error if a user clicks the button without selecting a value.
HTH
mmcdonal
|