Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / December 2005

Tip: Looking for answers? Try searching our database.

Timer in outlook

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
קובץ - 05 Dec 2005 17:08 GMT
hello!

I want to add a timer to my userform. how do I do that?

thanks!
Yonina.
Michael Bauer - 08 Dec 2005 07:31 GMT
Am Mon, 5 Dec 2005 09:08:02 -0800 schrieb קובץ:

> hello!
>
> I want to add a timer to my userform. how do I do that?
>
> thanks!
> Yonina.

Yonina, the MSForms don´t know a timer. You can use an API Timer instead.

Please add a standard module to your project (no class module). Copy the
code into it; you don´t need to change anything.

<modTimer>
Option Explicit
Private Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, _
 ByVal nIDEvent As Long, ByVal uElapse As Long, _
 ByVal lpTimerFunc As Long) As Long

Private Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, _
 ByVal nIDEvent As Long) As Long

Const WM_TIMER = &H113

Private hEvent As Long
Private m_oCallback As Object

Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, _
 ByVal wParam As Long, ByVal lParam As Long _
)
 If uMsg = WM_TIMER Then
   m_oCallback.Timer
 End If
End Sub

Public Function EnableTimer(ByVal msInterval As Long, oCallback As Object)
As Boolean
 If hEvent <> 0 Then
   Exit Function
 End If
 hEvent = SetTimer(0&, 0&, msInterval, AddressOf TimerProc)
 Set m_oCallback = oCallback
 EnableTimer = CBool(hEvent)
End Function

Public Function DisableTimer()
 If hEvent = 0 Then
   Exit Function
 End If
 KillTimer 0&, hEvent
 hEvent = 0
End Function
</modTimer>

Here comes a sample for how to use the timer. Please copy the code into
"ThisOutlookSession". There´re some usefull comments within the code.

<ThisOutlookSession>
' True means, the timer will be disabled after one event is raised.
' False means, the timer will raise an event again and again _
 for the given interval.
Private Const RUN_ONCE As Boolean = True

' Interval for the timer in milliseconds.
Private Const TIMER_INTERVAL As Long = 60000

' This function is necessary and is being called from the timer.
Public Sub Timer()
 If RUN_ONCE Then
   ' True disables the timer
   modTimer.DisableTimer
 End If
 
 ' Insert another code here, which shall be executed _
   by the timer events.
 ' ...
End Sub

' Sample for starting the timer immediately if Outlook starts.
Private Sub Application_Startup()
 modTimer.EnableTimer TIMER_INTERVAL, Me
End Sub

' Stops the timer if Outlook is being closed.
' NOTE: This doesn´t work in Outlook 2000!
Private Sub Application_Quit()
 modTimer.DisableTimer
End Sub
</ThisOutlookSession>

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.