Private Sub cmdApplyFilter_Click()
Dim strOffice As String
Dim strDepartment As String
Dim strGender As String
Dim strFilter As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "rptStaff") <> 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.Value & "'"
End If
' Build criteria string for Department field
If IsNull(Me.cboDepartment.Value) Then
strDepartment = "Like '*'"
Else
strDepartment = "='" & Me.cboDepartment.Value & "'"
End If
' Build criteria string for Gender field
SelectCase Me.fraGender.Value
Case 1
strGender = "='F'"
Case 2
strGender = "='M'"
Case 3
strGender = "Like '*'"
End Select
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[Office] " & strOffice & " AND [Department] " & strDepartment
_
& " AND [Gender] " & strGender
' Apply the filter and switch it on
With Reports![rptStaff]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![rptStaff].FilterOn = False
End Sub