Public Const conRunDate As Date = #7/20/90#
Function StartForm()
'*******************************************
'Name: StartForm (Function)
'Purpose: Run a procedure once a year, on
' or after a specified date.
'*******************************************
Dim dteRunDate As Date, dteLastRun As Date
Dim strSQL As String, msg As String, db As Database
'refers to public const conRunDate
dteRunDate = DateSerial(year(Date), Month(conRunDate), day(conRunDate))
'determines when the procedure was last run
dteLastRun = DLookup("MaxOfLastRun", "qryLastRun")
'since it's possible that the database won't be opened on the
'exact date, it's necessary to use Date >= rather than Date =
'it's also necessary to ensure that the process
'hasn't already run, eitherwise you'll end up with
'an endless loop
If Date >= dteRunDate And year(dteLastRun) < year(Date) Then
docmd.Beep 'your code to run the procedure would go here
Set db = CurrentDb
'adds new record to tblLastRun, showing today's date
strSQL = "INSERT INTO tblLastRun ( LastRun )SELECT Date() AS Expr1;"
'run the append query
db.Execute strSQL
msg = "LastRun date corrected to #" & Date & "#"
MsgBox msg, vbExclamation, "Procedure Alert"
db.Close
Set db = Nothing
'delete the following if desired
Else
msg = "Procedure last run on #" & dteLastRun & "#"
MsgBox msg, vbExclamation, "Procedure Alert"
End If
'do something else, in this case open the main form
docmd.OpenForm "z_WizMain", acNormal, , , , , "zf_Instructions"
End Function