Link to home
Start Free TrialLog in
Avatar of calibre74
calibre74

asked on

Microsoft Access VBA - count records with date comparisons

First of all I am still a novice with Microsoft Access VBA and queries.

I am trying to work out how I can count records in a MS Access 2010 table, based on comparing a date field with today's date in an Event Procedure within a form.

Basically I have the field "app date" in a table called "tblMain"and I want to count the number of records in which the "app date" was more than 1 calendar month ago. I am assuming this uses a DCount statement but I'm not sure how to implement this.

Any help would be greatly appreciated.
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Try something like this.  Post it in the SQL view, and update as needed with actual table/column names:


SELECT Count([app date]) AS Records
FROM [tblMain]
WHERE [app date] <= DateAdd("m", -1, Date())

Open in new window

As a DCount:



DCount("[app date]", "[tblMain]", "[app date] <= #" & Date() & "#")
Patrick:  Your DCount doesn't cut it.
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America 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
Now you've covered the bases.