S
scott
My table called "tblData" contains a datetime field called [dtDate]. This is
a sql table. I'm trying to pass a string called "DateString" as the WHERE
condition in my sql statement and return the record count.
The "DateString" variable will always look like 20060509 which stands for
the date 5/9/2006. I've tried 2 different ways in CODE 1 and CODE 2, but
both methods return 1150, the total records in the "tblData" table.
How can I "convert" a string like "20060509" into a date so I can use it as
a date in my where clause? Do I need a delimiter?
CODE 1 ***********
Dim objRS2 As ADODB.Recordset, dtDate As Date, DateString As String
DateString = "20060509"
dtDate = CDate(DateSerial(Val(Left(DateString, 4)), Val(Mid(DateString,
5, 2)), Val(Right(DateString, 2))))
CODE 2 ***********
Dim objRS2 As ADODB.Recordset, dtDate As Date, DateString As String
DateString = "2006-05-09"
dtDate = CDate(DateString)
MAIN CODE *********** (below code works right)
Set objRS2 = New ADODB.Recordset
objRS2.ActiveConnection = CurrentProject.Connection
objRS2.CursorType = adOpenStatic
objRS2.Open "SELECT * from tbldata WHERE dtDate >=" & dtDate
If objRS2.RecordCount > 0 Then
MsgBox "Records Exist: " & objRS2.RecordCount
Else
MsgBox "Records DON'T Exist: " & objRS2.RecordCount
End If
a sql table. I'm trying to pass a string called "DateString" as the WHERE
condition in my sql statement and return the record count.
The "DateString" variable will always look like 20060509 which stands for
the date 5/9/2006. I've tried 2 different ways in CODE 1 and CODE 2, but
both methods return 1150, the total records in the "tblData" table.
How can I "convert" a string like "20060509" into a date so I can use it as
a date in my where clause? Do I need a delimiter?
CODE 1 ***********
Dim objRS2 As ADODB.Recordset, dtDate As Date, DateString As String
DateString = "20060509"
dtDate = CDate(DateSerial(Val(Left(DateString, 4)), Val(Mid(DateString,
5, 2)), Val(Right(DateString, 2))))
CODE 2 ***********
Dim objRS2 As ADODB.Recordset, dtDate As Date, DateString As String
DateString = "2006-05-09"
dtDate = CDate(DateString)
MAIN CODE *********** (below code works right)
Set objRS2 = New ADODB.Recordset
objRS2.ActiveConnection = CurrentProject.Connection
objRS2.CursorType = adOpenStatic
objRS2.Open "SELECT * from tbldata WHERE dtDate >=" & dtDate
If objRS2.RecordCount > 0 Then
MsgBox "Records Exist: " & objRS2.RecordCount
Else
MsgBox "Records DON'T Exist: " & objRS2.RecordCount
End If