E
egun
I'm experimenting with OLEDB and SQL, and the simple query I'm trying to
perform doesn't work:
Dim startDate As Date, endDate As Date
Dim conData As New ADODB.Connection
Dim rstAssigns As New ADODB.Recordset
Dim strSelect As String
'
startDate = "4/1/2005"
endDate = "5/25/2012"
'
(Open connection to a Project file here - this part works fine)
'
strSelect = _
"SELECT TaskID, TaskName, TaskStart, TaskFinish FROM Tasks WHERE "
& _
"TaskStart >= '" & Format(startDate, "yyyy-mm-dd") & _
"' AND " & _
"TaskStart <= '" & Format(endDate, "yyyy-mm-dd") & _
"' ORDER BY TaskID ASC"
rstAssigns.CursorLocation = adUseClient
rstAssigns.CursorType = adOpenStatic
rstAssigns.Open strSelect, conData
The Open command returns 0 records every time, though I KNOW there are lots
of records between the two input dates. I have tried using BETWEEN also,
with the same results (or lack thereof), and many variations of the above.
Other queries, such as 'TaskID BETWEEN 5 and 50', work just fine. What is
wrong with my approach? I'm sure it has something to do with selecting on
dates, I just can't figure it out.
Thanks,
Eric
perform doesn't work:
Dim startDate As Date, endDate As Date
Dim conData As New ADODB.Connection
Dim rstAssigns As New ADODB.Recordset
Dim strSelect As String
'
startDate = "4/1/2005"
endDate = "5/25/2012"
'
(Open connection to a Project file here - this part works fine)
'
strSelect = _
"SELECT TaskID, TaskName, TaskStart, TaskFinish FROM Tasks WHERE "
& _
"TaskStart >= '" & Format(startDate, "yyyy-mm-dd") & _
"' AND " & _
"TaskStart <= '" & Format(endDate, "yyyy-mm-dd") & _
"' ORDER BY TaskID ASC"
rstAssigns.CursorLocation = adUseClient
rstAssigns.CursorType = adOpenStatic
rstAssigns.Open strSelect, conData
The Open command returns 0 records every time, though I KNOW there are lots
of records between the two input dates. I have tried using BETWEEN also,
with the same results (or lack thereof), and many variations of the above.
Other queries, such as 'TaskID BETWEEN 5 and 50', work just fine. What is
wrong with my approach? I'm sure it has something to do with selecting on
dates, I just can't figure it out.
Thanks,
Eric