Questions

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

+
0 Votes
Locked

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

Deacq
Hello,
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!

Clarifications

john.a.wills

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.

Deacq

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.