filter results based on two combo boxes

I don't think this is a cascading combobox issue.

I need to filter my query results based on two combo boxes - I want the combo boxes to work like an AND operator, rather than just filter the results on the last combobox. I also have a tickbox that should filter on one field, and I'd like that combined into the filter somehow.

Right now, I have a combobox that lists staff - selecting it shows the results filtered by staff. Great.
I also have a combobox that lists calls assigned to a team, selecting it shows all calls for that team. Perfect.
I have a tickbox to filter only open calls (unticking it lists all calls open or otherwise). This is based on a field in the table "isClosed".

What I want is to select either combobox and have the results updated based on the value in both boxes, and include the tickbox into the equation, allowing me to chose any combination of combobox and tick status, and get the results I want.

Can someone point me in the right direction please?

Thanks in advance!
LVL 2
RossAsked:
Who is Participating?
 
RossConnect With a Mentor Author Commented:
Ok sorted this myself.
0
 
RossAuthor Commented:
I've found some code I can apply to my situation:
Private Sub cmdFilter_Click()
On Error GoTo Err_cmdFilter_Click

Dim strSQL As String, intCounter As Integer
     'Build SQL String
For intCounter = 1 To 5

    If Me("Filter" & intCounter) <> "" Then
    
        If intCounter > 2 Then
        strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & CInt(Me("Filter" & intCounter)) & " And "
        
        Else
        
        strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
        
        End If
    
    End If

Next
     
     If strSQL <> "" Then
        'Strip Last " And "
        strSQL = Left(strSQL, (Len(strSQL) - 5))
        'Set the Filter property
        Me.Filter = strSQL
        Me.FilterOn = True
     Else
        Me.FilterOn = False
     End If

Exit_cmdFilter_Click:
    Exit Sub

Err_cmdFilter_Click:
    Resume Exit_cmdFilter_Click
    
End Sub

Open in new window


I've named my combo boxes "filter1" and "filter2".

Just struggling still. I'll keep you updated.
0
 
RossAuthor Commented:
Ok - I now have this working with my two combo boxes based on using and adapting the above code. But I'm stumped when trying to intruduce the checkbox into the search string. Any pointers please?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.