Filter Form Combo Box Query

robjam

New member
Local time
Today, 18:21
Joined
Jul 22, 2013
Messages
7
Hi,

I have created a form that searches a table to show certain criteria. I am having trouble with a part where the table uses a checkbox and I am trying to use a combo box on the search form to return the results based on is it checked? Yes/No or both. When I test it I keep getting Runtime error 3075 missing operator.

The sql I am using is below and when I try and see where it is going wrong it highlights the
Code:
Me.Filter = strWhere
line. Can anyone help me?

Code:
Private Sub cmdFilter_Click()

Dim strWhere As String
    Dim lngLen As Long
    Const conJetDate = "\#dd\/mm\/yyyy\#"
    
If Not IsNull(Me.txtFilterSupplier) Then
        strWhere = strWhere & "([Name] Like ""*" & Me.txtFilterSupplier & "*"") AND "
    End If
    
If Not IsNull(Me.txtFilterOrderedBy) Then
        strWhere = strWhere & "([Ordered By] Like ""*" & Me.txtFilterOrderedBy & "*"") AND "
    End If
    
If Not IsNull(Me.txtFilterBrand) Then
        strWhere = strWhere & "([Brand] Like ""*" & Me.txtFilterBrand & "*"") AND "
    End If
    
If Me.cboFilterMatched = -1 Then
    strWhere = strWhere & "([Matched] = True) AND"
ElseIf Me.cboFilterMatched = 0 Then
    strWhere = strWhere & "([Matched] = False) AND"
End If
    
       
lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then
        MsgBox "No criteria", vbInformation, "Nothing to do."
    Else
        strWhere = Left$(strWhere, lngLen)
        
        Debug.Print strWhere
        
        Me.Filter = strWhere
        Me.FilterOn = True
    End If
    
    
End Sub

Thanks
 
looks like you are missing a space after the AND

Code:
If Me.cboFilterMatched = -1 Then
    strWhere = strWhere & "([Matched] = True) AND"
ElseIf Me.cboFilterMatched = 0 Then
    strWhere = strWhere & "([Matched] = False) AND"
End If
But you could simplify this code to

Code:
strWhere = strWhere & "([Matched] = " & Me.cboFilterMatched & " AND "
 

Users who are viewing this thread

Back
Top Bottom