I have this coding for a user form that allows them to select a date range & a status, Open or Closed. This is the coding I have but I think there is something missing.
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("Range")
' 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)
End If
' Date Range criteria
strCriteria = strCriteria & "StartDate = " & "EndDate"
' Build the new SQL statement incorporating the string
strSQL = "SELECT * FROM [Vendor Hotline Log] " & _
"WHERE " & strCriteria & ";"
' Apply the new SQL statement to the query
Debug.Print strSQL
qdf.SQL = strSQL
' Open the query
DoCmd.OpenReport "Date Range", acViewPreview
DoCmd.Close acForm, "Search Criteria Form", acSaveNo
End Sub