How do I make a date field (variable) work in a VBA statement? - TechRepublic
Question
February 10, 2012 at 12:29 PM
deacq

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

by deacq . Updated 14 years, 4 months ago

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!

This discussion is locked

All Comments