VBA query asking for Parameter

Lol999

Registered User.
Local time
Today, 02:09
Joined
May 28, 2017
Messages
184
Got a strange one here because I have used what i thought was exactly the same syntax in another query string and gotten no problems.
I'm passing the value of a combobox to a string and executing it as a query in vba, but I keep getting asked for a parameter.
I've checked the control name, done debug.print for the value and that is coming out correctly but I keep getting asked for the parameter.
The code is below and I've attached a screenshot of the error message:
Code:
"SELECT Tbl_Costing.EmpName, Sum(Tbl_Costing.HoursWorked) AS SumOfHoursWorked, Tbl_Costing.WeekEnding FROM Tbl_Costing WHERE Tbl_Costing.EmpName= " & Cbo_EmpName.Value & "  And Tbl_Costing.WeekEnding Between #" & Format(CDate(Txt_StartDate.Value), "mm/dd/yy") & "# And #" & Format(CDate(Txt_EndDate.Value), "mm/dd/yy") & "# GROUP BY Tbl_Costing.Empname, Tbl_Costing.Weekending;"

Hope someone can point out the idiot mistake :-)
 

Attachments

  • Query Paramater value.jpg
    Query Paramater value.jpg
    37 KB · Views: 86
As EmpName is a text field you need text delimiters

'" & cboEmpName.value &"'
 
Text values need delimiters:

WHERE Tbl_Costing.EmpName= '" & Cbo_EmpName.Value & "' And

Use Chr(34) if there could be apostrophes in names.
 
Many thanks folks, much appreciated as Microsoft's info on this sort of thing is buried deeper than a deeply buried thing!
 

Users who are viewing this thread

Back
Top Bottom