Filtering form on True-False check boxes

  • Thread starter Thread starter EHPorter
  • Start date Start date
E

EHPorter

I have a form that contains the number of clients. The underlying table has
a few check box fields (Yes/No) for classifications such as Inactive?
Closed? and Problems?

Normally, I want the form to display all clients. Sometimes, however, it
would be nice to have the form display only those clients who's Problems?
box is checked "true." I'm looking for a simple way to add a control to the
form that would do this -- say, for example, a box I could check that, when
checked, filtered the form to display only Problem clients, while when
unchecked caused the form to display all clients.

I am not sure what would be the best way to go about doing this -- and how
to do it, once I know what I should be doing. Any thoughts would be
appreciated.
 
This example assumes you have *unbound* check boxes on your form (probably
in the form header), and you want to apply a filter based on whichever ones
are checked. It visits each one, building up a filter string from the ones
that are True, and then applies it to the filter of the form:

Dim strFilter As String
Dim lngLen As Long

If Me.chkProblems.Value Then
strFilter = strFilter & "(Problems = True) AND "
End If
If Me.chkInactive.Value Then
strFilter = strFilter & "(Inactive = True) AND "
End If
'etc for other boxes.
lngLen = Len(strFilter) - 5 'Without trailing " AND ".
If lngLen <=0 Then
Me.FilterOn = False
Else
strFilter = Left$(strFilter, lenLen)
Me.Filter = strFilter
Me.FilterOn = True
End If
 
Back
Top