0
votes

I have this two combobox on my form. Each one filters the form independently. but I want to filter the form based on both selections.

I have this code to a check box after update event to filter the form with the two combo box but it doesn't work:

combo19 is the name for the first combo box and combo21 is the name for the second combobox.

Private Sub Check34_AfterUpdate()
 Me.Filter = Me.Combo19 & Me.Combo21
 Me.FilterOn = True
 Me.Refresh

End Sub
1
Every time you don't rename controls to meaningful names and use the default names (Combo19, Check34) in code, a kitten dies. :(Andre

1 Answers

1
votes

The Filter property is a string expression consisting of a WHERE clause without the WHERE keyword. For example, the following Visual Basic code defines and applies a filter to show only customers from the USA:

Me.Filter = "Country = 'USA'" 
Me.FilterOn = True

https://msdn.microsoft.com/en-us/vba/access-vba/articles/form-filter-property-access

In your case, it would look like:

Me.Filter = "field1 = '" & Me.Combo19 & "'" & " AND field2 = '" & Me.Combo21 & "'"  

Where Field1 and Field2 should be replaced with the actual column names in your recordsource.
Also, your code doesn't check if Combo19 or Combo21 is empty.