-
Hi,
I'm trying to create a Timer Control within a module so
that it can be used in routines from any form.
I have tried:
Dim TestTmr As Timer
Sub Form_Load
TestTmr.Interval = 5000
End Sub
But this code causes an undefined object or missing with type error.
How do I set up a Timer object in code rather than on a
form?
Any help greatly appreciated.
Thanks
James
-
You can use the SetTimer and KillTimer API's, ie.
In a Module..
Code:
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private iTimerID As Long
Public Sub StartTimer(ByVal Interval As Long)
If iTimerID = 0 Then iTimerID = SetTimer(0&, 0&, Interval, AddressOf TimerCallback)
End Sub
Public Sub StopTimer()
If iTimerID Then Call KillTimer(0&, iTimerID)
iTimerID = 0
End Sub
Private Sub TimerCallback(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
'Do whatever in the Timer Event Here.
End Sub
Usage:
Code:
Private Sub Form_Load()
StartTimer 5000
End Sub
Private Sub Form_Unload()
StopTimer
End Sub
-
Hello GeoMEM,
Try this code:
Declarations:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Call Sleep(5000)
End Sub
Good luck,
Michelle.