I have a Public Function that is being auto executed when my database opens. It is designed to change the value of a record from "Trailing" to "Critical" when the record is older than 90 days. Everything works as expected initially by changing the status and adding some text to a comment field for tracking purposes. However, I manually flipped the status of those records back to "Trailing" for continued testing purposes and they are no longer being included in the code execution. Do recordsets have a cache that is identifying these records as already having been updated and is, therefore, excluding them for all future executions of this module? Code is below. I added a counter just for the purposes of testing and it's counting zero records, even though there are several records that meet the necessary criteria.
Public Function Trailing()
Dim strSQL As String
Dim db As Database
Dim rs As Recordset
Dim i As Integer
Dim ND As Date
Dim CT As Integer
ND = Now() - 90
strSQL = "INSERT INTO ModuleRunDate ([Run_Date]) VALUES (Now())"
If DMax("Run_Date", "ModuleRunDate") < Date Then
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Exceptions")
CT = 0
rs.MoveLast
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
If rs.Fields("Status") = "Trailing" And _
IsNull(rs.Fields("Date Completed")) And _
rs.Fields("Date of Exception") < ND Then
CT = CT + 1
rs.Edit
rs.Fields("Status") = "Critical"
rs.Fields("Comments") = rs.Fields("Comments").Value & "; Trailing to Critical " & Format(Now(), "mm/dd/yy")
rs.Update
End If
rs.MoveNext
Next i
MsgBox CT, vbOKOnly
rs.Close
Set rs = Nothing
db.Close
DoCmd.RunSQL strSQL
Else: Exit Function
End If
End Function
Public Function Trailing()
Dim strSQL As String
Dim db As Database
Dim rs As Recordset
Dim i As Integer
Dim ND As Date
Dim CT As Integer
ND = Now() - 90
strSQL = "INSERT INTO ModuleRunDate ([Run_Date]) VALUES (Now())"
If DMax("Run_Date", "ModuleRunDate") < Date Then
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Exceptions")
CT = 0
rs.MoveLast
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
If rs.Fields("Status") = "Trailing" And _
IsNull(rs.Fields("Date Completed")) And _
rs.Fields("Date of Exception") < ND Then
CT = CT + 1
rs.Edit
rs.Fields("Status") = "Critical"
rs.Fields("Comments") = rs.Fields("Comments").Value & "; Trailing to Critical " & Format(Now(), "mm/dd/yy")
rs.Update
End If
rs.MoveNext
Next i
MsgBox CT, vbOKOnly
rs.Close
Set rs = Nothing
db.Close
DoCmd.RunSQL strSQL
Else: Exit Function
End If
End Function