[red]Option Compare Database
Option Explicit[/red]
[green][b]'DO NOT duplication the above lines in your code module[/b][/green]
Dim vTimeToRun As Date
Dim vDownloadInProgress As Boolean
Dim vLastDownloadDate As Date
[b]Private Sub Form_Load()[/b]
vTimeToRun = DLookup("Download_StartTime", "tblDBParameters")
vDownloadInProgress = DLookup("DownloadInProgress", "tblDBParameters")
vLastDownloadDate = DLookup("LastDownload_Date", "tblDBParameters")
Me!TimerInterval = 900000 [green]'Set to 15 minute[/green] intervals
If vDownloadInProgress Then
MsgBox "Download in Progess. Try again in 5 minutes."
Application.Quit
End If
End Sub
[b]Private Sub Form_Timer()[/b]
If Time() > (vTimeToRun - 15) And Me.TimerInterval = 900000 Then
Me.TimerInterval = 60000
End If
If vLastDownloadDate < Date And Time() > vTimeToRun And vDownloadInProgress = False Then
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblDBParameters", dbOpenDynaset)
rs.MoveFirst
rs.Edit
rs("DownloadInProgress") = True
vDownloadInProgress = True
rs.Update
rs.Close
[green][b]'put your code to run reports or queries here[/b][/green]
Set rs = db.OpenRecordset("tblDBParameters", dbOpenDynaset)
rs.MoveFirst
rs.Edit
rs("DownloadInProgress") = False
rs("LastDownload_Date") = Date
vLastDownloadDate = Date
vDownloadInProgress = False
rs.Update
rs.Close
db.Close
Me.TimerInterval = 900000
Else
'download completed for today.
End If
End Sub