Filter by date

  • Thread starter ernestb08 via AccessMonster.com
  • Start date
E

ernestb08 via AccessMonster.com

I want to filter my records from a week's past.
I'm using vba code.
I got the button to work for the current date filter:

DoCmd.ApplyFilter , "Date = Date()"

Now I'm trying to filter my records for the current date minus 7 days with
the following:
show all records from: 10-25-2006 back to 10-18-2006.

Me.Filter = "Date() - 7" or Me.Filter = "Date() - Date()-7"

DoCmd.ApplyFilter , "Date() - 7" or DoCmd.ApplyFilter, "Date()-Date()-7"

It appears everytime it returns all of my records after I press the button.

Any Help will be appreciated.

Thanks, Ernie
 
D

Douglas J. Steele

A filter has to include the name of the field in the underlying recordset
being filtered.

If the field in the recordset is named Date (a very bad choice, by the way,
as it's a reserved word and can lead to many problems), you need:

Me.Filter = "[Date] Between Date() And Date()-7"

If you cannot (or will not) change the field name, at least enclose it in
square brackets as I did above)
 
E

ernestb08 via AccessMonster.com

Douglas said:
A filter has to include the name of the field in the underlying recordset
being filtered.

If the field in the recordset is named Date (a very bad choice, by the way,
as it's a reserved word and can lead to many problems), you need:

Me.Filter = "[Date] Between Date() And Date()-7"

If you cannot (or will not) change the field name, at least enclose it in
square brackets as I did above)
I want to filter my records from a week's past.
I'm using vba code.
[quoted text clipped - 17 lines]
Thanks, Ernie

I was able to perfom what I wanted, Thanks for the help. Ernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top