June7,
Thank you for that reference. I redid my control form using VBA and it operates much better. I have used a lot of VBA in Excel but didn’t know where to start in Access. This was a great starting point.
I recommend a small addition to Allen Browne’s script. A small problem you will encounter is that he only tests if the checkbox in the details section is on (-1) or off (0). He says that it isn’t necessary to test for the both condition (1) since “we add nothing to the filter string for other cases (1 or Null).”
Code:
'Yes/No field and combo example. If combo is blank or contains "ALL", we do nothing.
If Me.cboFilterIsCorporate = -1 Then
strWhere = strWhere & "([IsCorporate] = True) AND "
ElseIf Me.cboFilterIsCorporate = 0 Then
strWhere = strWhere & "([IsCorporate] = False) AND "
End If
While this will still work for most cases, we run into a problem if the only thing we want to filter is the “both” condition(1) because no other criteria is entered and therefore, the routine will default to his error message “no criteria”. To avoid this we should still test for the “both” condition (1)
Code:
'Yes/No field and combo example. If combo is blank or contains "ALL", we do nothing.
If Me.cboFilterIsCorporate = -1 Then
strWhere = strWhere & "([IsCorporate] = True) AND "
ElseIf Me.cboFilterIsCorporate = 0 Then
strWhere = strWhere & "([IsCorporate] = False) AND "
ElseIf Me.cboFilterIsCorporate = 1 Then
strWhere = strWhere & "([IsCorporate] = True Or [IsCorporate] = False) AND "
End If
By adding the third test condition for(1) we now avoid the error message IF no other criteria is entered.