So this should be an easy one I'm sure.
I have a standard SQL datetime column, I want to grab all entries for the last 24 hours preferably, using vba in excel, ive dumbed the problem down to "just the last calender days" to try and get a better idea on how to solve this and cannot figure out how to proceed.
basically: VBA will accept if I manually enter a date into the "between" part of the sql statement, but won't accept a variable with the date.
Playing around it "appears" that vba is formatting fields declared as dates as mm/dd/yyyy instead of yyyy/mm/dd in a standard Datetime column in sql, which is probably the problem! I've been playing around with the convert command, but to no avail. It does work if I manually enter dates correctly formatted into the variable values though.
code below:
Dim DateVar As Date
Dim DateStart As Date
Dim DateEnd As Date
DateVar = Range("A2").Value
DateStart = DateVar - 1
DateEnd = DateVar + 1
adoDbConn.Open **CONNECTION STRING GOES HERE**
selectCmd.ActiveConnection = adoDbConn
selectCmd.CommandText = "SELECT DateTime, Machine_Number, FROM [33_TestImport]
Where Machine_Number = " & Machvar & "
AND DateTime BETWEEN " & DateVar & " AND " & DateEnd &
ORDER By DateTime "