Avatar of KP_SoCal
Flag for United States of America

asked on 

Creating multiple form controls to filter records in a subform...

For simplicity's sake, in my Access 2010 database form that contains a subform, let's say I have three check box controls (I actually have much more than three) that I'm using to filter records in an embedded subform.

As you can see from my code below, when Me.chkBoxFilter1 is checked, only records for fldFilter1= True are displayed. When unchecked, all records are displayed.

If IsNull(Me.chkBoxFilter1) Then
   Me.subformColorSurrogation.Form.Filter = ""
   Me.subformColorSurrogation.Form.FilterOn = False

  Me.subformColorSurrogation.Form.Filter = "[fldFilter1]=" & Me.chkBoxFilter1
  Me.subformColorSurrogation.Form.FilterOn = True
End If

Open in new window

I'm looking for a way I can add or remove other filters through the use of my other check boxes. I know I could accomplish this through multiple ELSEIF statements, but is there a way, for instance, when clicking M.chkBoxFilter2 to TRUE, to ONLY pull TRUE records for fldFilter2 without unfiltering the restrictions placed by my other checkboxes?

I hope this makes sense. I really appreciate any insight into this.
DatabasesMicrosoft AccessVBA

Avatar of undefined
Last Comment
Mark Edwards

8/22/2022 - Mon