Good Night,
I have a report called "ExamTimeTablebydate" which I am trying to make dynamic by creating a form with 2 combo boxes that will supply the criteria that changes the form. The combo boxes are "cboOffice" and "cboDepartment". There is a button called "cmdApplyFilter" that triggers the query on the form.
The fields in "ExamTimeTablebydate" which are associated with the query are "Class" and "Venue".
The problem is that when values are placed in the combo box and the "cmdApplyFilter" button is press, the report comes up empty, but when the combo boxes are emptied the table is once again fully loaded with values.
Is there a plausible explanation for this?
Here is my code:
Option Compare Database
Private Sub Form_Load()
DoCmd.OpenReport "ExamTimeTablebydate", acViewPreview
End Sub
Private Sub cmdApplyFilter_Click()
Dim strOffice As String
Dim strDepartment As String
Dim strFilter As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "ExamTimeTablebydate") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for Office field
If IsNull(Me.cboOffice.Value) Then
strOffice = "Like '*'"
Else
strOffice = "='" & Me.cboOffice & "'"
End If
' Build criteria string for Department field
If IsNull(Me.cboDepartment.Value) Then
strDepartment = "Like '*'"
Else
strDepartment = "='" & Me.cboDepartment & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[Class] " & strOffice & " AND [Venue] " & strDepartment
' Apply the filter and switch it on
With Reports![ExamTimeTablebydate]
.Filter = strFilter
.FilterOn = True
End With