Running function everyday automatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to automatically run a macro or query, everyday at 3:30pm. What
is the best method to do this? I do not want any user intervention. It needs
to run in the "background", as long as the Access file remains open....And
lets assume its always open...., and can be triggered to start in the
autoexec macro when the file is opened....

Thanks.
 
If you have a form that is guaranteed to be open the whole time the
database is open, use that. Otherwise, create a little form just for the
purpose, set its Visible property to False and open it in the AutoExec
macro.

If you already have a "Settings" table, add a record to it to store the
date when your macro last ran. If you don't, create one.

Either way, set the form's TimerInterval to reasonable interval (say
one second, one minute or five minutes depending on how close to 3:30
you need the macro or query to run). In the OnTimer event procedure, do
this (pseudocode):

If Time() >= 13:30
And Nz(date macro last ran, 0) < Date() Then
Run Macro
Date macro last ran = Date()
End If

Rather than running a macro, I'd use VBA code to do whatever's required.
This would make it possible to include some error handling:

If Time() >= 13:30
And Nz(date task last done, 0) < Date() Then
Do my task
If task succeeeded Then
Date task last done = Date()
End If
End If
 
Back
Top