Link to home
Start Free TrialLog in
Avatar of mtrussell
mtrussell

asked on

Dcount using a date in a table compared to today's date

This should be straight forward but it isn't.  I am trying to count the number of records in a table where the date in a field is less than the current date.  What I have is the below but it is kicking out an error code.

=DCount([id],[Tbl_ClientCommunication],"[calcdate] & Date()")

Does anyone know how to write this so it works?
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

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
That code is prone to localization errors if used in regions (or on computers) where the dateformat doesn't match the US date format.
The following should work  in all regions:
DCount([id],[Tbl_ClientCommunication],"[calcdate] <Date()")

Open in new window

In Bill's code, the Date is first interpreted by VBA, and formatted according to regional settings. In the second case, the date() is called directly by the database engine, and you avoid any regional issues.
Sorry Bill. Anders is right. Your code will fail on this side.

/gustav