Turning off form's timer

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

Guest

How do I turn off the form's timer when the application (MS Access) is not
the active application, and turn on the form's timer when it is the active
application?

This approach would enable the timer code only executes when the application
is active.
 
Hi,

You may start with something like:

Option Compare Database
Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () As Long

Private Sub Private Sub Form_Timer()

If GetForegroundWindow() <> Me.hWnd Then
Call DoSomeJob( )
Else
Me.TimerInterval=0 ' disable the timer
End If

End Sub



Note that the timer interval WON'T be restarted automatically to a non-zero
value. You may use the OnActivate or the OnEnter event to re-specify a
non-zero value for the form TimerInterval.



Hoping it may help,
Vanderghast, Access MVP
 
Thanks for your reply.

Since my app is a single form with size set to maximize, I cannot re-specify
a
non-zero value for the form TimerInterval using OnActivate or the OnEnter
events. Do you have another suggestion?
 
Hi,

Unfortunately, no. Access, the environment, does not expose event by its
own. You may try to "preview" all keystroke, by the form, and there,
re-initialize the timer interval if it is equal to 0....



Hoping it may help
Vanderghast, Access MVP
 
Hi,


Me.KeyPreview=True


or the property (under Event) Key Preview set to No by default.



Hoping it may help,
Vanderghast, Access MVP
 
Thanks for your help.

Michel Walsh said:
Hi,


Me.KeyPreview=True


or the property (under Event) Key Preview set to No by default.



Hoping it may help,
Vanderghast, Access MVP
 
Back
Top