Visual Basic/VBA Timer event happens in a from based on the setting (in
milliseconds) of the Timer Interval form property. You can use the timer
event to create stop watch functions within Access databases.
Microsoft Access Timer Event Example:
In the Timer Event example we cause a time of day text field to
be updated every 10 seconds.
First we set the TimerInterval of the database form to be 10000
milliseconds, then:
Private Sub Form_Timer()
Me!Time_of_Day= Time
End Sub
Now for a more useful example of the Timer and On Timer
event. If you want MS Access to perform some operation at a regular
interval then you can use the timer interval and timer event in combination to
run some action.
In the example below we establish a time
interval for the form of 10000 milliseconds (10 seconds).
Then
the timer event procedure contains code to requery the form. So the form
gets requeried every 10 seconds. You could have the database perform most
any action.. Such as running a report, Sending/receiving emails, popup
meeting reminders, etc.
The only problem with this method is that
the database has to be up and running for the repetitive action to occur.
If you don't want to have the database running continuously then you can use
Windows task scheduler to run the database at regular intervals. In that
case there is no need to have the event timer code.
Private Sub
Form_Open(Cancel As Integer)
Me.TimerInterval = 10000
End Sub
Private Sub Form_Timer()
Me.Requery
MsgBox "requery"
End Sub