?
Solved

Filter a continuous form

Posted on 2006-05-26
7
Medium Priority
?
225 Views
Last Modified: 2008-03-17
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?
0
Comment
Question by:dewster1971
  • 3
5 Comments
 
LVL 27

Expert Comment

by:MikeToole
ID: 16771245
You will also need me.FilterOn = True
0
 

Author Comment

by:dewster1971
ID: 16771314
So what's the entire code look like?

me.FilterOn = True
Me.Filter =  [Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 16771438
You will need to Apply the filter ...

DoCmd.ApplyFilter

ET
0
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 1000 total points
ID: 16771765
Actually, this should work for you ...

DoCmd.ApplyFilter, "[Visit Month]=2" & " AND " & "Year([VisitDate]) = " & Me.cboYear

ET
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 16772057
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
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question