dewster1971
asked on
Filter a continuous form
I have a form that I would like to filter based on the month and year. I have copied over a form that had the follow code behind a command button. In this form, there is not original strCoreFilter. I simply want the filter to be
Me.Filter = strCoreFilter & IIf(Trim(strCoreFilter) <> "", " AND ", "") & " [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
I simply want the filter to be:
[Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
but when I try Me.Filter = [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear, I don't get any filtering to work properly.
I will also have several other command buttons for other months and I would need to be able to restore all data before running the next filter. Clear, I hope so.
Any suggestions?
Me.Filter = strCoreFilter & IIf(Trim(strCoreFilter) <> "", " AND ", "") & " [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
I simply want the filter to be:
[Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
but when I try Me.Filter = [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear, I don't get any filtering to work properly.
I will also have several other command buttons for other months and I would need to be able to restore all data before running the next filter. Clear, I hope so.
Any suggestions?
You will also need me.FilterOn = True
ASKER
So what's the entire code look like?
me.FilterOn = True
Me.Filter = [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
me.FilterOn = True
Me.Filter = [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
You will need to Apply the filter ...
DoCmd.ApplyFilter
ET
DoCmd.ApplyFilter
ET
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to use this method then you will need the code in this order ...
Me.Filter = [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
me.FilterOn = True
ET
Me.Filter = [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
me.FilterOn = True
ET