View Single Post
  #2 (permalink)  
Old February 6th, 2006, 09:13 AM
mmcdonal mmcdonal is offline
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
Reply With Quote