Alternative code......
I don't know the field types in your table(s), but here is your code rewritten WITHOUT the check boxes.
This is based off of code provided by Allen Browne: Search Criteria
Code:
Option Compare Database
Option Explicit
Private Sub btnSearch_Click()
Dim filterText As String
Dim lngLen As Long
'Text field example. Use quotes around the value in the string.
If Not IsNull(Me.cboCust) Then
filterText = filterText & "cust_nb= '" & Me.cboCust & "' AND "
End If
'Text field
If Not IsNull(Me.cboPart) Then
filterText = filterText & "partNumber= '" & Me.cboPart & "' AND "
End If
'Text field
If Not IsNull(Me.cboFail) Then
filterText = filterText & "failureCategory= '" & Me.cboFail & "' AND "
End If
'Text field
If Not IsNull(Me.cboMonth) Then
filterText = filterText & "Month(dateReceived)= '" & Me.cboMonth & "' AND "
End If
'Number field
If Not IsNull(Me.txtYear) Then
filterText = filterText & "Year(dateReceived)= " & Me.txtYear & " AND "
End If
'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(filterText) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
filterText = Left$(filterText, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
'Debug.Print filterText
'Finally, apply the string as the form's Filter.
Me.Filter = filterText
Me.FilterOn = True
Me.Refresh
End If
End Sub
To remove filter
Code:
Private Sub btnRemoveFilter_Click()
Me.cboCust = vbNullString
Me.cboPart = vbNullString
Me.cboFail = vbNullString
Me.cboMonth = vbNullString
Me.txtYear = vbNullString
Me.Filter = vbNullString
Me.FilterOn = False
End Sub