CarlRostron
New Member
- Joined
- May 11, 2011
- Messages
- 26
My first post on this forum and I thank all helpers in advance.
I am using Excel 2007. I am running a VBA SQL query on some data in a sheet. Most of my SQL queries work fine apart from the one with dates.
I have tried alsorts to try and debug as to why it isnt working and have resorted to get some help from you guys.
The snippet of code is thus:
........Other code............
Dim aDate As Date
aDate = Format("22/07/2011", "Short Date")
strQuery = "SELECT * FROM [Sheet1$A1:L302] WHERE ([Want Date] > " & aDate & ");"
Sheets("Output").Range("A1").Value = strQuery
If (strQuery = "") Then
Set ResultSet = Query("SELECT * FROM " & MyRange & ";")
Else
'strQuery = "SELECT * FROM " & MyRange & _
' " WHERE " & strQuery
Set ResultSet = Query(strQuery)
End If
........Other code............
Just to confirm the SQL Query going in to the query function I have is:
SELECT * FROM [Sheet1$A1:L302] WHERE ([Want Date] > 22/07/2011);
This as far as I can see is valid. However, the Result Set being returned contains records that are earlier than 22/7/2011.
Please can someone help me to identify as to where this is going wrong? The dates in the sheet are fomatted to 'Short Date'.
Thanks
I am using Excel 2007. I am running a VBA SQL query on some data in a sheet. Most of my SQL queries work fine apart from the one with dates.
I have tried alsorts to try and debug as to why it isnt working and have resorted to get some help from you guys.
The snippet of code is thus:
........Other code............
Dim aDate As Date
aDate = Format("22/07/2011", "Short Date")
strQuery = "SELECT * FROM [Sheet1$A1:L302] WHERE ([Want Date] > " & aDate & ");"
Sheets("Output").Range("A1").Value = strQuery
If (strQuery = "") Then
Set ResultSet = Query("SELECT * FROM " & MyRange & ";")
Else
'strQuery = "SELECT * FROM " & MyRange & _
' " WHERE " & strQuery
Set ResultSet = Query(strQuery)
End If
........Other code............
Just to confirm the SQL Query going in to the query function I have is:
SELECT * FROM [Sheet1$A1:L302] WHERE ([Want Date] > 22/07/2011);
This as far as I can see is valid. However, the Result Set being returned contains records that are earlier than 22/7/2011.
Please can someone help me to identify as to where this is going wrong? The dates in the sheet are fomatted to 'Short Date'.
Thanks