I am trying to run an strSQL within Excel VBA between two date ranges.
See below part of my code relevant to this:
Dim DateMin As String
Dim DateMax As String
DateMin = Format$(Sheets("Setup").Range("c5").Value, "mm/dd/yyyy")
DateMax = Format$(Sheets("Setup").Range("c6").Value, "mm/dd/yyyy")
strSQL = "SELECT [COSTCENTRE_CODE],[PROJECT_CODE],[HOME_VALUE],[CT_DEADLINE] FROM [AA_CST_CENTRE_TRANSACTION_SIMPLE_VIEW] where [CT_DEADLINE] between #" & DateMin & "# AND #" & DateMax & "#"
When I run this I get an "incorrect syntax nea '#'" error. The format of cells C5 + C6 are in the same mm/dd/yyyy format - am using the American date format as believe SQL only uses American dates? I have tried adjusting the dates but no luck.
When I run "debug.print strsql" I get the below:
SELECT [COSTCENTRE_CODE],[PROJECT_CODE],[HOME_VALUE],[CT_DEADLINE] FROM [AA_CST_CENTRE_TRANSACTION_SIMPLE_VIEW] where [CT_DEADLINE] between #02/01/2020# AND #03/31/2020#
I have tried removing the #
around the dates and I no longer get the error, however no data shows at all - there is definitely data there for these dates.
Anyone have any ideas as believe this is an SQL issue rather than an Excel VBA issue?