Been searching for a Timer Event solution to use in Outlook 2003 to complete a workaround (zero-budget) project ... use of the W32 API mSec Sleep Function is one option but apparently comes with the potential to crash the OS and or slow down other apps
Was excited to find these examples of using Reminders to simulate a timer event, however, I must be missing some key concept(s) ... numerous attempts to get this code to run all fail to trigger an actual EVENT (tried all 3 Event possibilities; Reminder, Snooze, BeforeReminderShow) ... my results suggest that the "EVENT HANDLER" code is never called
Found this link that describes how to use WithEvents
https://bettersolutions.com/vba/even...dule-level.htm
Could someone Please confirm whether the following 5 details (based on the above link) are applicable to the examples in this thread?
1) WithEvents statements must be defined within the header of a CLASS MODULE
2) Event-related vars & code(functions|subs) appear to be defined within the same CLASS MODULE
3) Application_Start is suggested to be defined in ThisOutlookSession (appears to work from a Module as well)
4) Global Objects related to CLASS should be defined within a Module header
5) Application_Start needs to create a NEW instance of any CLASS Objects referencing their Global Objects
- this isn't clear from the link but my take is an EVENT HANDLER MUST BE AVAILABLE (PERSISTENT) to be run
(a global object is persistent)
- perhaps an EVENT HANDLER can still be defined as a non-class method in some Module
Update: the Event Handler BeforeReminderShow still not running:
' thisOutlookSession
Option Explicit
Sub Application_Startup() ' automatically run each time Outlook is started ...
Set oADI_TMR = New cmADI_TMR
Dim tsk As Outlook.TaskItem
' create initial task
Set tsk = Application.CreateItem(olTaskItem)
tsk.Subject = "ADI_TMR" ' This item is showing up in the task list and when it times out it is popping up a Reminder Dialog
tsk.StartDate = Format(Now, "mm/dd/yyyy")
tsk.ReminderSet = True
tsk.ReminderTime = DateAdd("n", 1, Now)
tsk.Save
Debug.Print Now; "AS "; tsk.ReminderTime
End Sub
Sub tstCode()
Debug.Print Now; "some test code"
End Sub
This just contains the Global oADI_TMR object
' Module mdADI_TMR
Option Explicit
Public oADI_TMR As cmADI_TMR
The oADI_TMR object was created but the B4 event isn't run resulting in the popup showing up
' Class Module cmADI_TMR
Option Explicit
Public WithEvents myReminders As Outlook.reminders
Private Sub Class_Initialize()
debug.print now ; "oADI_TMR has been created"
End Sub
' expected this sub to stop the Reminder popup plus it is supposed to snooze the reminder
Private Sub myReminders_BeforeReminderShow(Cancel As Boolean)
Dim rmd As Outlook.Reminder
Set rmd = myReminders.Item(1) ' This is an unattended process there should only ever be one reminder
If rmd.Caption = "ADI_TMR" Then
Debug.Print Now; " b4 … calling test code"
rmd.Snooze (1)
Call ThisOutlookSession.tstCode ' call the process we want to run every minute
Debug.Print Now; " snz "; rmd.NextReminderDate
Cancel = False ' shouldn't need to destroy scheduled reminder because it was snoozed
End If
End Sub