A
Alan
Hello All
Sorry but really struggling with this Date Query
I have a table that holds Dates and times (General Date Format) of various
daily server logs that I import to an Access Database. Each log is date
stamped and this table provides the last date of import to allow the next
file to be selected.
I also have a table that after importing the logs then takes a number of
counts from the logs which it updates in this table against a date value
(Primary Key of table)
My probelm is with the lookup and access to the date.
I have used a recordset to access the table as below, but the issue appears
to be with how the date is being formatted after it leaves the vba statement.
As can be seen below I have tried reformating the date value at the
beginningbut to no avail. I have also tried removing the format in the Set
Recordset SQL
Public Sub getcount()
Dim rstDateUpdate As Recordset
Dim rstTestCount As Recordset
Dim dtSrvrDate As Date
Set rstDateUpdate = CurrentDb.OpenRecordset("SELECT * FROM tblServerImports
WHERE (tblServerImports.ServerName)='TestServer'")
With rstDateUpdate
' dtSrvrDate = Format(Left(.Fields("LatestFiledate"), 10), "mm\/dd\/yyyy")
dtSrvrDate = Left(.Fields("LatestFiledate"), 10)
' dtSrvrDate = Int(.Fields("LatestFiledate"))
End With
Set rstTestCount = CurrentDb.OpenRecordset("SELECT tblServerCounts.* FROM
tblServerCounts WHERE (((tblServerCounts.Date)=#" & Format(dtSrvrDate,
"dd\/mm\/yyyy") & "#))", dbOpenDynaset)
With rstTestCount
MsgBox rstTestCount.RecordCount
End With
End Sub
There is a record for the date being searched therfore count should be 1 but
returns 0 (this is also the trigger in the main code to create a new entry if
no date exists)
Any Help would be gratefully appreciated
Kind Regards
Sorry but really struggling with this Date Query
I have a table that holds Dates and times (General Date Format) of various
daily server logs that I import to an Access Database. Each log is date
stamped and this table provides the last date of import to allow the next
file to be selected.
I also have a table that after importing the logs then takes a number of
counts from the logs which it updates in this table against a date value
(Primary Key of table)
My probelm is with the lookup and access to the date.
I have used a recordset to access the table as below, but the issue appears
to be with how the date is being formatted after it leaves the vba statement.
As can be seen below I have tried reformating the date value at the
beginningbut to no avail. I have also tried removing the format in the Set
Recordset SQL
Public Sub getcount()
Dim rstDateUpdate As Recordset
Dim rstTestCount As Recordset
Dim dtSrvrDate As Date
Set rstDateUpdate = CurrentDb.OpenRecordset("SELECT * FROM tblServerImports
WHERE (tblServerImports.ServerName)='TestServer'")
With rstDateUpdate
' dtSrvrDate = Format(Left(.Fields("LatestFiledate"), 10), "mm\/dd\/yyyy")
dtSrvrDate = Left(.Fields("LatestFiledate"), 10)
' dtSrvrDate = Int(.Fields("LatestFiledate"))
End With
Set rstTestCount = CurrentDb.OpenRecordset("SELECT tblServerCounts.* FROM
tblServerCounts WHERE (((tblServerCounts.Date)=#" & Format(dtSrvrDate,
"dd\/mm\/yyyy") & "#))", dbOpenDynaset)
With rstTestCount
MsgBox rstTestCount.RecordCount
End With
End Sub
There is a record for the date being searched therfore count should be 1 but
returns 0 (this is also the trigger in the main code to create a new entry if
no date exists)
Any Help would be gratefully appreciated
Kind Regards