• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

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

Db-why-not

Registered User.
Local time
Today, 09:32
Joined
Sep 17, 2019
Messages
123
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
Today, 07:32
Joined
Oct 29, 2018
Messages
12,496
Try:
Code:
Me.Filter = "[mth]=" & ComboContentsMth & " AND [Yr]=" & ComboContentsYr
 

Isaac

Lifelong Learner
Local time
Today, 07:32
Joined
Mar 14, 2017
Messages
2,389
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