Hi,
I am having trouble in setting up this form. There is a table that contains all vendor calls we have gotten. On the form for data entry I have a button that when clicked another form appears so that the user can select a date range and can have select one or more selections for the "Status" of each call. This is the code for that 2nd form. I also have a query that allows the date range selection & Status selection in the form. This will all be brought up in a report once selected. This is the coding that I get the Compile error message. The qdf.SQL = strSQL is what is highlighted with the error message. Any help would be greatly appreciated.
I am having trouble in setting up this form. There is a table that contains all vendor calls we have gotten. On the form for data entry I have a button that when clicked another form appears so that the user can select a date range and can have select one or more selections for the "Status" of each call. This is the code for that 2nd form. I also have a query that allows the date range selection & Status selection in the form. This will all be brought up in a report once selected. This is the coding that I get the Compile error message. The qdf.SQL = strSQL is what is highlighted with the error message. Any help would be greatly appreciated.
Code:
Private Sub OK_Click()
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDefs
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!Status.ItemsSelected.Count > 0 Then
For Each varItem In Me!Status.ItemsSelected
strCriteria = strCriteria & "Vendor Hotline Log.Status = " & Chr(34) _
& Me!Status.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
' Open the query
DoCmd.OpenQuery "Copy of Date Range Query"
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub