ACC: Dynamic Query to Return Records for the Previous MonthID: Q176645
|
Moderate: Requires basic macro, coding, and interoperability skills.
This article demonstrates how to create a query that returns all the
records in which the value of a Date field falls within the previous month.
To create a query that returns the data from the previous month based on
the current date, use the Between...And operator with the DateSerial()
function in the Criteria of the Date field. The DateSerial() function
returns a date for a specified year, month, and day. The syntax of the
DateSerial() function is:
DateSerial(year, month, day)
Query: qryLastMonth
---------------------------------------------------------
Type: Select Query
Field: OrderID
Table: Orders
Field: OrderDate
Table: Orders
Field: RequiredDate
Table: Orders
Field: ShippedDate
Table: Orders
Criteria: Between DateSerial(Year(Date()),Month(Date())-1,1) And
DateSerial(Year(Date()),Month(Date()),0)
DateSerial(97,1,0)
12/31/96
For more information about the Between...And operator, search the Help
Index for "Between...And operator."
For more information about the DateSerial() function, search the Help Index
for "DateSerial."
For more information about other expressions to manipulate dates, see the
following article in the Microsoft Knowledge Base:
Q88657 ACC: Functions for Calculating and Displaying Date/Time
Values
Additional query words: prior before earlier
Keywords : QryHowto QryCrit
Version : WINDOWS:2.0,7.0,97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 23, 1999