Hi, all -
I am seeking to open a query through VBA which uses a multiselection list box as a parameter. I got the code primarily from searching online.
I'm getting the "The Select statement includes a reserved word or an argument name that is misspelled or missing" etc. I'm not finding anything that seems reserved or whatever so extra eyes would be very much appreciated.
Below is the code:
Any help would be appreciated.
Thanks.
I am seeking to open a query through VBA which uses a multiselection list box as a parameter. I got the code primarily from searching online.
I'm getting the "The Select statement includes a reserved word or an argument name that is misspelled or missing" etc. I'm not finding anything that seems reserved or whatever so extra eyes would be very much appreciated.
Below is the code:
Code:
Set db = CurrentDb()
Set qdf = db.QueryDefs("qrySWCaseCounts")
Set ctl = Me.lstEmployees
For Each varItem In ctl.ItemsSelected
strCriteria = strCriteria & "," & Me!lstEmployees.ItemData(varItem) & ""
Next varItem
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT P.StaffID, D.ReportDate AS AsOf, Count(P.PtID) AS Day_Case_Count " & _
"FROM tblCaseAssign AS P INNER JOIN tblDates_Reports AS D ON P.StartDate <= D.ReportDate AND P.EndDate >= D.ReportDate " & _
"WHERE P.StaffID IN(" & strCriteria & ") " & _
"GROUP BY P.StaffID, D.ReportDate " & _
"ORDER BY P.StaffID, D.ReportDate; "
Debug.Print strSQL
qdf.sql = strSQL
DoCmd.OpenQuery "qrySWCaseCounts"
Set db = Nothing
Set qdf = Nothing
Any help would be appreciated.
Thanks.
Last edited: