Something is not right with my SQL string

spnz

Registered User.
Local time
Today, 05:42
Joined
Feb 28, 2005
Messages
84
Good morning,

I am trying to use an SQL statement to add a value into a listbox.

This is my code
Code:
Private Sub lstSearchResults_DblClick(Cancel As Integer)
        
    Dim strPayRollNumber As String
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strQuery As String
    Dim strFilterSQL As String
    
    Me.RecordsetClone.FindFirst "PersonalID = " & Me.lstSearchResults
    Me.Bookmark = Me.RecordsetClone.Bookmark
    DoCmd.GoToControl ("pgePersonalInformation")

    
    strPayRollNumber = Me.txtPayRollNumber.Value
    
    Set db = CurrentDb
    Set qdf = db.QueryDefs("qry2YWH")
    
    

    strQuery = "SELECT tblPersonalInformation.PayRollNumber,Count(tblTickReports.WeekEnding) AS CountOfWeekEnding"
    strQuery = strQuery & " FROM tblPersonalInformation INNER JOIN tblTickReports ON tblPersonalInformation.PayRollNumber = tblTickReports.PayrollNumber"
    strQuery = strQuery & " GROUP BY tblPersonalInformation.PayRollNumber, tblTickReports.RateType"
    strQuery = strQuery & " HAVING ((tblTickReports.RateType)='standard') AND ((tblPersonalInformation.PayrollNumber) = '" & strPayRollNumber & "');"

    Debug.Print strQuery
    qdf.SQL = strQuery

   Me.lstWeeksWorked.RowSource = "qry2YWH"
    
    Set qdf = Nothing
    Set db = Nothing


End Sub

Basically what I am wanting to do is use the above query and have the result populate a listbox that I have on a form.

Something is wrong with the SQL Statement I am trying to use. I started by using the query designer then copied it over into VBA and slightly modified it.

Can anyone see what I have done wrong with the statement?

Thanks for your help.
 
((tblPersonalInformation.PayrollNumber) = '" & strPayRollNumber & "');"
You sure this 'number' is a string?

Try
((tblPersonalInformation.PayrollNumber) = " & strPayRollNumber & ");"
 

Users who are viewing this thread

Back
Top Bottom