Web Development



How do I make a date field (variable) work in a VBA statement?

By Deacq ·
I have a table which has a date field named 'icu_admit'. I am trying to retrieve the number of records between specific date periods, for example one specific date range can be 01-Feb-2011 to 31-Aug-2011.

I inserted the start and end date in the following statement: Total_Recs = DCount("[icu_admit]", "LOS_table", "[icu_admit] >= #01-Feb-2011# And [icu_admit] <= #31-Aug_2011#") which returned the correct number of records.

Since I have numerous start and end dates, I tried to replace the actual dates with the variables 'start_date' and 'end_date' in the statement, then define the start and end with different dates. That did not work and instead I received the error message "The expression you entered as a query parameter produced this error 'The object doesn't contain the Automation object 'start_date'.

How can I build a statement to accomplish this? Your help will be greatly appreciated. -Thanks!

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Request for Clarification

by john.a.wills In reply to Clarifications

Please show us the query statement (with the preceding few statements) which leads to the error message. It may be that you are using the variables start_date and end_date in the query rather than their values.

Collapse -

Request for Clarification

by Deacq In reply to Clarifications

Yes, I am using the variables start_date and end_date in my query which was causing the error. I will have to change my logic Thanks for your insight.

Related Discussions

Related Forums