View Full Version : Query /Filter Show X months worth of records


ChrisPhysics
07-13-2007, 06:16 AM
Can someone help?

I need the code for a filter or query which will show the past x (12, 24 etc) months worth of data. Each record has a date tag so i need a filter which will just show records for say the past 3 months.

Any ideas?

Gethzerion
07-13-2007, 07:10 AM
How do you want the user to select the number of months worth of records?

In the QBE, for the query, under the date tag field, place in the criteria row a >=DateAdd("m",-x,Date())

Where x is the number of months

ChrisPhysics
07-13-2007, 07:24 AM
That works really well thanks.

Ideally i'd like to use a pop up form to enter the number of months. If I no one can help me with that then i'll just use a series of preset queries.

raskew
07-13-2007, 08:01 AM
Chris -

Read-up on Parameter Queries. Here's a simple example you can try (substitute your table and field names).

PARAMETERS x Short;
SELECT tblDevProcess.*
FROM tblDevProcess
WHERE (((tblDevProcess.startTime)>=DateAdd("m",-[x],Date())));


Bob

ChrisPhysics
07-13-2007, 08:09 AM
Thanks. Wow I love Parameter queries!