Hi,
I am getting a syntax error on a form that I am trying to make multi-select work. There is a date rage the user can choose but also if something is open or closed or both. The error is Syntax Error (missing operator) in query expression 'Vendor Hotline Log.Status = "Closed" OR Vendor Hotline Log.Status = "Open"'. It then highlights this line in the coding Apply the new SQL statement to the query
qdf.SQL = strSQL See full code below
I am getting a syntax error on a form that I am trying to make multi-select work. There is a date rage the user can choose but also if something is open or closed or both. The error is Syntax Error (missing operator) in query expression 'Vendor Hotline Log.Status = "Closed" OR Vendor Hotline Log.Status = "Open"'. It then highlights this line in the coding Apply the new SQL statement to the query
qdf.SQL = strSQL See full code below
Code:
Private Sub OK_Click()
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("Copy of Date Range Query")
' Loop through the selected items in the list box and build a text string
If Me!Status1.ItemsSelected.Count > 0 Then
For Each varItem In Me!Status1.ItemsSelected
strCriteria = strCriteria & "Vendor Hotline Log.Status = " & Chr(34) _
& Me!Status1.ItemData(varItem) & Chr(34) & " OR "
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "Vendor Hotline Log.Status Like '*'"
End If
' Build the new SQL statement incorporating the string
strSQL = "SELECT * FROM [Vendor Hotline Log] " & _
"WHERE " & strCriteria & ";"
' Apply the new SQL statement to the query
qdf.SQL = strSQL
Debug.Print strSQL
' Open the query
DoCmd.OpenQuery "Copy of Date Range Query"
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub