Insert static criteria to query from code

Lochwood

Registered User.
Local time
Today, 13:36
Joined
Jun 7, 2017
Messages
130
I am trying to set criteria of query2 with the value from a combobox. At the moment the code will fill the criteria with the form field location but i need the criteria to show the actual value. so if my combobox shows value 193 and i run the code, it would add 193 to the criteria. can you help?. here is my code

Private Sub Command243_Click()
Dim db As dao.Database
Set db = CurrentDb
Dim qdf As dao.QueryDef

Set qdf = db.QueryDefs("Query2")
qdf.SQL = "Select * From [Query1] WHERE [Job Number] =Forms![Personal_Details_Form]![Job_No_Combo] "

End Sub
 
Maybe this:
Code:
qdf.SQL = "Select * From [Query1] WHERE [Job Number] =[B][COLOR=Red]" & Me.[Job_No_Combo][/COLOR][/B]
 
The sql will use the value of the bound column in the combo.
Usually that column is hidden.
Check the row source of your combo
If you want to use a different combo column you need to save that as a variable for use in your sql
Depending on how you intend to run this you may need delimiters around the Forms!....part
 

Users who are viewing this thread

Back
Top Bottom