G
Guest
I have the following code running properly when used on text fields. It
fails when I sub a number field. I sub Group in my strWhere statement with
GroupID and it fails. Can anyone help me with the correct syntax?
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strWhere As String
Dim i As Integer
Set db = CurrentDb
'*** create the query based on the information on the form
strSQL = "SELECT tblProduct.* tblProduct "
strWhere = "Where Group IN( "
For i = 0 To lstClass.ListCount - 1
If lstClass.Selected(i) Then
strWhere = strWhere & "'" & lstClass.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
strSQL = strSQL & strWhere
'*** delete the previous query
db.QueryDefs.Delete "qryMyQuery"
Set qdf = db.CreateQueryDef("qryMyQuery", strSQL)
'*** open the query
DoCmd.OpenQuery "qryMyQuery", acNormal, acEdit
Exit_cmdOK_Click:
Exit Sub
Err_cmdOK_Click:
MsgBox Err.Description '*** write out the error and exit the sub
Resume Exit_cmdOK_Click
End Sub
fails when I sub a number field. I sub Group in my strWhere statement with
GroupID and it fails. Can anyone help me with the correct syntax?
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strWhere As String
Dim i As Integer
Set db = CurrentDb
'*** create the query based on the information on the form
strSQL = "SELECT tblProduct.* tblProduct "
strWhere = "Where Group IN( "
For i = 0 To lstClass.ListCount - 1
If lstClass.Selected(i) Then
strWhere = strWhere & "'" & lstClass.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
strSQL = strSQL & strWhere
'*** delete the previous query
db.QueryDefs.Delete "qryMyQuery"
Set qdf = db.CreateQueryDef("qryMyQuery", strSQL)
'*** open the query
DoCmd.OpenQuery "qryMyQuery", acNormal, acEdit
Exit_cmdOK_Click:
Exit Sub
Err_cmdOK_Click:
MsgBox Err.Description '*** write out the error and exit the sub
Resume Exit_cmdOK_Click
End Sub