SQL query use variable instead of hard coded dates?
Posted on 2013-06-25
I'm pulling data from an SQL database via MS access 2010. The SQL query works fine with the date and time hard coded. However, the user needs to set the start and end date and time manually.
For this I'm using a date picker and formating the date/time returned to yyyy-mm-dd 00:00:00 which is stored in a string variable (although I think the 102 in the convert statement means yy.mm.dd??)
How would I use this variable instead of the hard coded date? I'm really no good with SQL!
Here is the end part of the SQL query
BETWEEN CONVERT(DATETIME, '2013-06-01 00:00:00', 102) AND CONVERT(DATETIME, '2013-06-07 00:00:00', 102)) AND (TMSACMON.LOGNO IN (35, 36, 37, 5)) ORDER BY TMSACMON.ACDATE"
The SQL is being executed in VBA like this..
Set objMyCmd.ActiveConnection = objMyConn
objMyCmd.CommandText = "Blah Blah"
objMyCmd.CommandType = adCmdText