Applying Multiple Filters to a Form Using Check Boxes (1 Viewer)

surg3mast3r

New member
Local time
Yesterday, 18:44
Joined
May 13, 2016
Messages
3
I can get a check box to apply a filter when selected and to remove the filter when not selected;

Code:
Private Sub High_check_Click()

If High_check = True Then

Me.Filter = "Priority = 'High'"

Me.FilterOn = True

Else

Me.FilterOn = False

End If

End Sub

But I don't know how to get it so that if i have two boxes ticked at once it will apply a joint filter. eg. if i had 'high' and 'medium' ticked then it will return all the records that have a priority of high and medium (leaving all the low priority jobs off)

Any ideas?
 

Ranman256

Well-known member
Local time
Yesterday, 21:44
Joined
Apr 9, 2015
Messages
4,337
Test all controls for a possible filter then build the where clause.
Code:
sWhere = "1=1"
If High_check.value  then   sWhere = sWhere & " AND [priority] = 'High'"
If chkBox2.value  then   sWhere = sWhere & " AND [field] = 'setting'"


     'just use the filter

  me.filter = sWhere
  me.filterOn = true
 

surg3mast3r

New member
Local time
Yesterday, 18:44
Joined
May 13, 2016
Messages
3
That works as individual check boxes, but if both are checked then its looking for a record with both a high and a low priority not high OR low.
Code:
Private Sub Command198_Click()
sWhere = "1=1"
If High_check.Value Then sWhere = sWhere & " AND [priority] = 'High'"
If low_check.Value Then sWhere = sWhere & " AND [priority] = 'low'"


     'just use the filter

  Me.Filter = sWhere
  Me.FilterOn = True
End Sub
 

Users who are viewing this thread

Top Bottom