Private Sub cmdOK_Click()
    Dim varItem As Variant
    Dim strOffice As String
    Dim strDepartment As String
    Dim strGender As String
    Dim strDepartmentCondition As String
    Dim strGenderCondition As String
    Dim strSQL As String
' Build criteria string for Office
    For Each varItem In Me.lstOffice.ItemsSelected
        strOffice = strOffice & ",'" & Me.lstOffice.ItemData(varItem) & "'"
    Next varItem
    If Len(strOffice) = 0 Then
        strOffice = "Like '*'"
    Else
        strOffice = Right(strOffice, Len(strOffice) - 1)
        strOffice = "IN(" & strOffice & ")"
    End If
' Build criteria string for Department
    For Each varItem In Me.lstDepartment.ItemsSelected
        strDepartment = strDepartment & ",'" & Me.lstDepartment.ItemData(varItem) & "'"
    Next varItem
    If Len(strDepartment) = 0 Then
        strDepartment = "Like '*'"
    Else
        strDepartment = Right(strDepartment, Len(strDepartment) - 1)
        strDepartment = "IN(" & strDepartment & ")"
    End If
' Build criteria string for Gender
    For Each varItem In Me.lstGender.ItemsSelected
        strGender = strGender & ",'" & Me.lstGender.ItemData(varItem) & "'"
    Next varItem
    If Len(strGender) = 0 Then
        strGender = "Like '*'"
    Else
        strGender = Right(strGender, Len(strGender) - 1)
        strGender = "IN(" & strGender & ")"
    End If
' Get Department condition
    If Me.optAndDepartment.Value = True Then
        strDepartmentCondition = " AND "
    Else
        strDepartmentCondition = " OR "
    End If
' Get Gender condition
    If Me.optAndGender.Value = True Then
        strGenderCondition = " AND "
    Else
        strGenderCondition = " OR "
    End If
' Build SQL statement
    strSQL = "SELECT tblStaff.* FROM tblStaff " & _
             "WHERE tblStaff.[Office] " & strOffice & _
             strDepartmentCondition & "tblStaff.[Department] " & strDepartment & _
             strGenderCondition & "tblStaff.[Gender] " & strGender & ";"
' Send the SQL statement to Immediate Window
    Debug.Print strSQL
' Display the SQL statement in a message box
    MsgBox strSQL
End Sub

Private Sub optAndDepartment_Click()
' Toggle the option buttons
    If Me.optAndDepartment.Value = True Then
        Me.optOrDepartment.Value = False
    Else
        Me.optOrDepartment.Value = True
    End If
End Sub


Private Sub optAndGender_Click()
' Toggle the option buttons
    If Me.optAndGender.Value = True Then
        Me.optOrGender.Value = False
    Else
        Me.optOrGender.Value = True
    End If
End Sub

Private Sub optOrDepartment_Click()
' Toggle the option buttons
    If Me.optOrDepartment.Value = True Then
        Me.optAndDepartment.Value = False
    Else
        Me.optAndDepartment.Value = True
    End If
End Sub

Private Sub optOrGender_Click()
' Toggle the option buttons
    If Me.optOrGender.Value = True Then
        Me.optAndGender.Value = False
    Else
        Me.optAndGender.Value = True
    End If
End Sub