Filter question

arage

Registered User.
Local time
Today, 08:39
Joined
Dec 30, 2000
Messages
537
Filter question

Here’s my code:

Private Sub cmd2002_Click()
'remove filter..
DoCmd.ShowAllRecords
'add filter..
DoCmd.ApplyFilter , Right(Me![MediaStartDate], 1) = 2
End Sub

It appears in my form & is meant to remove the form’s filter & then apply a filter that will return records that apply to the year 2002. However currently the form will return a blank new record instead of a 2002 records. I do have some 2002 records & the forms onCurrent event is not causing the problem either.
 
What happens if you use
DoCmd.ApplyFilter, DatePart("yyyy",[MediaStartDate]) = 2002
?

Unless your date field isn't of date type, this should work more reliably. You could even make it search for the current year so you don't have to change it every year, or make a parameter out of it.
 
Your code will allow originally filtered records to remain onscreen rather than going to a new record like mine did. Basically not worrking.

A note that my records are initially filtered in vba code before I start trying to replace it with my new filter.
 
my date is stored in mm/dd/yy format but when I format your code to this:

DoCmd.ApplyFilter, DatePart("yy",[MediaStartDate]) = “02”

I get an error message about an invalid procedure call or argument.
 
Well, I was only trying to change the one line in your code, you should still use DoCmd.ShowAllRecords beforehand if you want to remove all previous records.
 

Users who are viewing this thread

Back
Top Bottom