Sub MasterSchedule()
Dim DB As Database, RS As Recordset, curtask As String, Tries As Byte
Dim TaskStatus As Variant, FileName As String
If errorhandlingon Then On Error GoTo ErrHandle
logerror "Utilities MasterSchedule starting"
Set DB = CurrentDb
Set RS = DB.OpenRecordset("masterschedulePrioritized", dbOpenDynaset)
RS.MoveFirst
Do Until RS.EOF
If RS!NextSchedTime < Now And InStr(1, RS!SchedWkDay, Weekday(Date)) Then 'if task is due and it's an allowed day of the week
curtask = RS!Task
FileName = Nz(RS!Parameters, "") 'filename is an optional parameter. taskstatus() requires a string, so If null, set to zero length string
RS.Edit
RS!LastStart = Now() 'record start time
RS.Update
'run task
TaskStatus = TaskSuccess(curtask, FileName) 'run the task and report back on results
Set RS = DB.OpenRecordset("masterschedulePrioritized", dbOpenDynaset)
RS.FindFirst "task = '" & curtask & "' and parameters = '" & FileName & "'"
If TaskStatus = True Then
RS.Edit
RS!LastSuccess = Now() 'record success time and increment scheduled time
RS!NextSchedTime = IncrementSchedule(RS!NextSchedTime, RS!SchedWkDay, RS!Interval)
RS!Errors = ""
RS!Tries = 0
RS.Update
Else
RS.Edit
RS!Errors = Left(RS!Errors & " " & TaskStatus, 150) 'record errors
RS!Tries = RS!Tries + 1 're-try
If RS!Tries >= RS!TryLimit Then
RS!NextSchedTime = IncrementSchedule(RS!NextSchedTime, RS!SchedWkDay, RS!Interval)
RS!Errors = RS!Errors & " Gave up after " & RS!Tries & " tries."
RS!Tries = 0
End If
RS.Update
End If
SendAlarm curtask, CBool(TaskStatus), FileName
End If
RS.MoveNext
Loop
GoTo CloseAll
ErrHandle:
logerror "Utilities MasterSchedule Error"
CloseAll:
Set RS = Nothing
Set DB = Nothing
End Sub