Setting 2 filters at a time, not working (1 Viewer)

Db-why-not

Registered User.
Local time
Yesterday, 19:36
Joined
Sep 17, 2019
Messages
159
I'm trying to set 2 different filters at the same time but when I try to do both it doesn't work. I have 2 combo boxs, one with month, one for Year. I want to be able to select month and year and filter my year and month fields. for my continuous form. It works when I only have the code for one of the fields.

Code:
Private Sub cmdFilter_Click()

Dim ComboContentsMth  As String
Dim ComboContentsYr  As String

If (IsNull(Me.cboMonth) Or IsNull(Me.cboYear)) Then

MsgBox "Please select a month and year to filter"
Else

ComboContentsMth = Me.cboMonth
ComboContentsYr = Me.cboYear

Me.Filter = "[mth]= " & ComboContentsMth
Me.Filter = "[Yr]= " & ComboContentsYr
Me.FilterOn = True
 End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:36
Joined
Oct 29, 2018
Messages
21,358
Try:
Code:
Me.Filter = "[mth]=" & ComboContentsMth & " AND [Yr]=" & ComboContentsYr
 

Isaac

Lifelong Learner
Local time
Yesterday, 17:36
Joined
Mar 14, 2017
Messages
8,738
Just to add,

Code:
Me.Filter = "[mth]= " & ComboContentsMth
Me.Filter = "[Yr]= " & ComboContentsYr

Remember vba code executes sequentially. The first line sets the filter to one thing. The second line sets the filter to a totally different thing - at which point, the action that the first line performs is "erased"...
 

Users who are viewing this thread

Top Bottom