
Event listeners may be registered with the Reminders collection to handle reminder events when they fire. These events can monitor times when reminders (of any type) fire when a reminder is displayed or changed in Outlook. On this page we will review all the events related to the Reminders collection and provide some sample code so you can see what can be done with each.
Four types of items can have reminders:
- AppointmentItem
- MailItem
- ContactItem
- TaskItem
Place the following event code into the ThisOutlookSession module. This will initialize the event handlers that follow below.
Private WithEvents MyReminders As Outlook.Reminders Private Sub Application_Startup() Set MyReminders = GetOutlookApp.Reminders End Sub Function GetOutlookApp() As Outlook.Application ' returns reference to native Application object Set GetOutlookApp = Outlook.Application End Function
BeforeReminderShow Event
This event fires before the ReminderFire event, and just before the Inspector object associated with the reminder is displayed on screen. This code is placed in the ThisOutlookSession module along with the code above.
Private Sub MyReminders_BeforeReminderShow(Cancel As Boolean)
On Error GoTo ErrorHandler
If MsgBox("A reminder would like to display. Do you want to see this reminder?", _
vbYesNo) = vbNo Then
Cancel = True
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.number & " - " & Err.Description
Resume ProgramExit
End SubSince we don't have access to the object that the reminder is part of, the best we can do is prompt the user to cancel the event.
ReminderAdd Event
This event will fire after a new reminder is added to an appropriate item (AppointmentItem, MailItem, ContactItem or TaskItem) and the item is saved.
Private Sub MyReminders_ReminderAdd(ByVal ReminderObject As Reminder)
On Error GoTo ErrorHandler
Dim itemType As String
Select Case True
Case IsMeeting(ReminderObject), IsAppointment(ReminderObject)
itemType = "AppointmentItem"
Case IsMail(ReminderObject)
itemType = "MailItem"
Case IsContact(ReminderObject)
itemType = "ContactItem"
Case IsTask(ReminderObject)
itemType = "TaskItem"
End Select
MsgBox "This reminder is being added to a " & itemType & " object.", vbInformation
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.number & " - " & Err.Description
Resume ProgramExit
End SubThis event does pass in the relevant object, so we can check it for various properties and act accordingly. The ReminderObject has the following properties and methods:
- Application – returns a reference to the Application Object
- Caption – returns the window caption of the given reminder
- Class – returns the class of the Reminder object (101 or olReminder)
- Dismiss – dismisses the reminder, triggering the ReminderRemove Event
- IsVisible – returns True if the item is being displayed
- Item – returns a reference to the Reminder object
- NextReminderDate – returns a Date representing the next scheduled reminder date and time
- OriginalReminderDate – returns a Date that represents the date and time a reminder was originally scheduled
- Parent – returns the parent Object for the current Reminder Object (in this case, the Reminders Collection)
- Session – returns a Namespace Object representing the current session
- Size – returns the size of the reminder (in kb) – note that this is not documented on MSDN for Outlook 2003 or 2007
The Parent property can prove useful, for example when adding a reminder we can check to see if it's a duplicate.
Private Sub MyReminders_ReminderAdd(ByVal ReminderObject As Reminder)
On Error GoTo ErrorHandler
Dim reminderCollection As Outlook.Reminders
Dim reminderChild As Outlook.Reminder
Dim duplicateReminderCount As Long
Set reminderCollection = ReminderObject.Parent
For Each reminderChild In reminderCollection
' if the caption, reminder time and type are the same, it's a dupe!
If reminderChild.Caption = ReminderObject.Caption Then
If reminderChild.NextReminderDate = ReminderObject.NextReminderDate Then
If reminderChild.Class = ReminderObject.Class Then
duplicateReminderCount = duplicateReminderCount + 1
If duplicateReminderCount > 1 Then
Exit For
End If
End If
End If
End If
Next reminderChild
If duplicateReminderCount > 1 Then
MsgBox "This reminder looks like a duplicate of an existing reminder. Please check!", vbInformation
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.number & " - " & Err.Description
Resume ProgramExit
End SubReminderChange Event
This event will fire after a reminder has been changed. Unfortunately the reminder is passed ByVal so we cannot make any changes programmatically, nor prevent unauthorized changes to the item, but merely notify the user that a change has been made.
Private Sub MyReminders_ReminderChange(ByVal ReminderObject As Reminder)
On Error GoTo ErrorHandler
Dim itemType As String
Select Case True
Case IsMeeting(ReminderObject), IsAppointment(ReminderObject)
itemType = "AppointmentItem"
Case IsMail(ReminderObject)
itemType = "MailItem"
Case IsContact(ReminderObject)
itemType = "ContactItem"
Case IsTask(ReminderObject)
itemType = "TaskItem"
End Select
MsgBox "You changed a " & itemType & " object.", vbInformation
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.number & " - " & Err.Description
Resume ProgramExit
End Sub
Function IsTask(itm As Object) As Boolean
IsTask = (TypeName(itm) = "TaskItem")
End Function
Function IsMail(itm As Object) As Boolean
IsMail = (TypeName(itm) = "MailItem")
End Function
Function IsContact(itm As Object) As Boolean
IsContact = (TypeName(itm) = "ContactItem")
End Function
Function IsMeeting(itm As Object) As Boolean
IsMeeting = (TypeName(itm) = "AppointmentItem" And itm.MeetingStatus = olMeeting)
End Function
Function IsAppointment(itm As Object) As Boolean
IsAppointment = (TypeName(itm) = "AppointmentItem" And itm.MeetingStatus = olNonMeeting)
End FunctionReminderFire Event
The ReminderFire Event occurs just before the reminder is shown, and after the BeforeReminderShow Event. In this sample code, displayed reminders will be automatically dismissed.
Private Sub MyReminders_ReminderFire(ByVal ReminderObject As Reminder)
On Error GoTo ErrorHandler
' auto dismiss reminders, will fire ReminderRemove method
If ReminderObject.IsVisible Then
ReminderObject.Dismiss
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.number & " - " & Err.Description
Resume ProgramExit
End SubReminderRemove Event
This event occurs whenever a reminder is removed from the Reminders Collection. From MSDN:
A reminder can be removed from the Reminders collection by any of the following means:
The Reminders collection's Remove method.
The Reminder object's Dismiss method.
When the user clicks the Dismiss button.
When a user turns off a meeting reminder from within the associated item.
When a user deletes an item that contains a reminder.
Private Sub MyReminders_ReminderRemove() On Error GoTo ErrorHandler MsgBox "You removed my reminder. Boo." ProgramExit: Exit Sub ErrorHandler: MsgBox Err.number & " - " & Err.Description Resume ProgramExit End Sub
Snooze Event
This event fires whenever the Snooze button is clicked on a reminder, or if the Snooze method is executed. The NextReminderDate property is incremented accordingly. In this sample code, the next reminder date is checked to see if it is one day or more from the current date and time.
Private Sub MyReminders_Snooze(ByVal ReminderObject As Reminder)
On Error GoTo ErrorHandler
' if the reminder is at least one day, show warning
If ReminderObject.NextReminderDate > (Now + 1) Then
MsgBox "The next reminder time is pretty far from now.", vbExclamation
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.number & " - " & Err.Description
Resume ProgramExit
End Sub