Link to home
Start Free TrialLog in
Avatar of dkilby
dkilbyFlag for Canada

asked on

MS Access Query - current month

I am trying to create a couple of queries in MS Access that when opened show me all the data for the current month, and then another query that shows me all the data for the previous month, without having to enter dates, is this possible and if so how.

The date field is [Date of Call]

Thanks
Avatar of COACHMAN99
COACHMAN99

SELECT Tx.TX_ID, Tx.Cust_ID, Format([TX_Date],'mmm/yyyy') AS MM
FROM Tx
WHERE (((Format([TX_Date],'mmm/yyyy'))=Format(Now(),'mmm/yyyy')));

SELECT Tx.TX_ID, Tx.Cust_ID, Format(DateAdd('m',-1,[TX_Date]),'mmm/yyyy') as MM
FROM Tx
WHERE (((Format(DateAdd('m',-1,[TX_Date]),'mmm/yyyy'))=Format(DateAdd('m',-1,Now()),'mmm/yyyy')));
Avatar of Gustav Brock
You should never use mmm in SQL as it will fail in a non-English environment.

Use DateSerial.

This month:

Where YourDate Between
    DateSerial(Year(Date()), Month(Date(), 1) And
    DateSerial(Year(Date()), Month(Date() + 1, 0)

Previous month:

Where YourDate Between
    DateSerial(Year(Date()), Month(Date() - 1, 1) And
    DateSerial(Year(Date()), Month(Date(), 0)

/gustav
Try
... Format ([Date of Call], "yyyy/mm")=Format (Date(), "yyyy/mm") or Format ([Date of Call], "yyyy/mm")=Format (DateAdd("m",-1,Date()), "yyyy/mm")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial