Turning off form's timer

C

Charles Tam

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.
 
M

Michel Walsh

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
 
C

Charles Tam

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?
 
M

Michel Walsh

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
 
M

Michel Walsh

Hi,


Me.KeyPreview=True


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



Hoping it may help,
Vanderghast, Access MVP
 
C

Charles Tam

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top