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

Referencing a combo box value in a query

Status
Not open for further replies.

kenjones

Technical User
Jul 19, 2002
4
GB
I am trying to use a combo box on a form to allow a user to select a value with which to query a table. I have created the combo box using a query to retrieve the relevant values from the original table, and have written a separate query which works when I manually enter the value to search/retrieve. The difficulty I have is referencing the selection from the combo box as the value in the query with which to retrieve data.
 
You should be able to reference the combo box value in the query criteria using something like this:
[Forms]![Daily Activity Record]![DarId] where "Daily Activity Record" is the form name and "DarId" is the name of the combo box. If you right-click on the criteria box and choose build you should be able to build the criteria by browsing to the control you want to reference.
 
Hi there!

Try entering the following into the criteria of your select query:

Forms![your form's name]![your combo-box name]

This should be okay.

Regards

Magnetar [atom]
 
You reference the value of a combo box with comboboxname.Value

Just substitute the name of your combo box for comboboxname.

In the query, use the following syntax:

Text data: "'" & cmbobox.Value & "'"
Text data: Chr(34) & cmbobox.Value & Chr(34) (another option)
Numeric data: Trim(Str(cmbobox.Value))
Date data: "#" & cmbobox.Value & "#"

Example SQL strings:

"Select * From tblTest Where txtFld = " & Chr(34) & cmbobox.Value & Chr(34)"

"Select * From tblTest Where NumFld = " & Trim(Str(cmbobox.Value))"


dz
dzaccess@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top