ReminderFire not being trapped

C

Chris S.

I'm trying to tune a VBA in Outlook 2003 that I started months ago. I
can get the macro to work using the Application_Reminder within
ThisOutlookSession, but I can't figure out how to trap the
ReminderFire or ReminderRemove. There are a lot of examples I've
found for Application_Reminder, but very few on the other two. I
tried both DIM and PUBLIC on the Class module, neither made a
difference. Any help with code would be great!

<<ThisOutlookSession>>
Dim WithEvents objReminders As Outlook.Reminders
Dim WithEvents olApp As Outlook.Application
Dim WithEvents objRems As Outlook.Reminders
-------------------
Private Sub Application_Reminder(ByVal Item As Object)
'Dim olApp As Outlook.Application
'Dim objRems As Outlook.Reminders
'Dim objRem As Outlook.Reminder

Set olApp = Outlook.Application
Set objRems = olApp.Reminders
Set objReminders = Application.Reminders
.....
End Sub

<<Class Modules>> <<Class1>>
Private Sub objReminders_ReminderRemove()
'Occurs when a reminder is removed from the collection
'or the user clicks Dismiss

MsgBox "A reminder has been removed from the collection."

End Sub

Private Sub olApp_ReminderFire(ByVal ReminderObject As Reminder)
'Occurs when a reminder executes
'Set objRems = Nothing
'Set objRem = Nothing
Set SafeItem = Nothing

Set olApp = Outlook.Application
Set objRems = objReminders.Reminders

Dim i As Integer
Dim Start
Dim PauseTime
....
End Sub
 
K

Ken Slovak - [MVP - Outlook]

'<<ThisOutlookSession>>
Dim WithEvents objReminders As Outlook.Reminders

Private Sub Application_Startup()
Set objReminders = Application.Reminders
End Sub

Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
'whatever
End Sub

and so on for any other event you want to handle for the Reminders
collection.

If you want to use a class module instead of the ThisOutlookSession class
module you must instantiate the class in Application_Startup and then in the
class's Initialize event instantiate a class module level Reminders object
declared WithEvents.
 
C

Chris S.

Ken Slovak - said:
'<<ThisOutlookSession>>
Dim WithEvents objReminders As Outlook.Reminders

Private Sub Application_Startup()
Set objReminders = Application.Reminders
End Sub

Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
'whatever
End Sub

and so on for any other event you want to handle for the Reminders
collection.

If you want to use a class module instead of the ThisOutlookSession class
module you must instantiate the class in Application_Startup and then in the
class's Initialize event instantiate a class module level Reminders object
declared WithEvents.

Super, it worked! Got a follow-up now (surprised?)

I'm trying to find the fields of the reminder within the reminderfire
event I've setup. I'm using one of the MS examples and can see
caption, but not the start time, duration, body, subject and location.
How can I reference this info?

I'm going thru each reminder this way...

For i = objReminders.Count To 1 Step -1
If objReminders(i).IsVisible = True Then
Set objRem = olApp.Reminders.Item(i)

oSubject = "Reminder: " & objRem.Caption
oBody = _
"St: " & FormatDateTime(objRem.Start, vbLongTime) & vbCrLf &
_
"En: " & FormatDateTime(objRem.Duration, vbLongTime) &
vbCrLf & _
"Loc: " & objReminders(i).Location & vbCrLf & _
"Dtls: " & vbCrLf & objReminders(i).Caption
MsgBox "send chris cell reminder visible."

End If
 
K

Ken Slovak - [MVP - Outlook]

Are you sure you're getting an appointment item? Don't forget that tasks,
contacts and email items also can have reminders on them. I'd check for the
Class of each item you get to make sure it is an appointment.
 
C

Chris S.

I am working on appointments, just don't know to get to the fields in
my example below such as:
start time,
duration,
body,
subject,
and location
 
K

Ken Slovak - [MVP - Outlook]

If you are getting an appointment item (and I would still check for the
Class of the item anyway, it's better to be safe than sorry) just use the
properties of that item. If the item is objRem then:

objRem.Subject
objRem.Location
etc.

Look up the property names you want in the Object Browser, which lists all
properties and events and methods of each Outlook item and collection.
 
C

Chris S.

Hmmm, I'm obviously not setting this thing up right. I tried to
access objRem.Subject within the ReminderFire event and got run time
error 438. Object doesn't support this property or Method.
 
K

Ken Slovak - [MVP - Outlook]

Every Outlook item supports Subject, so I'd guess you are setting things up
wrong.

Rather than trying to go over all the posts in this thread and piecing
together the code you're using why not post the code again here and we can
look it over and see what's going on.
 
C

Chris S.

Thanks for checking this out -- I'm a hacker at this point...
------
Public WithEvents objReminders As Outlook.Reminders

Private Sub Application_Reminder(ByVal Item As Object)
Dim objRem As Outlook.Reminder
Set olApp = New Outlook.Application
Set objReminders = Application.Reminders

Dim i As Integer
Dim Start
Dim PauseTime
Dim DismissFlag

Dim SafeItem, oItem
Set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an
instance of Redemption.SafeMailItem
Set oItem = Application.CreateItem(0) 'Create a new message
SafeItem.Item = oItem 'set Item property
NOTE: OLD CODE BEFORE I TRIED REMINDERFIRE
SafeItem.Recipients.Add "(e-mail address removed)"
SafeItem.Recipients.ResolveAll
SafeItem.Subject = "Reminder: " & SubHold
' must handle all 4 types of items that can generate reminders

Select Case Item.Class
Case olAppointment '26
SafeItem.Body = _
"St: " & FormatDateTime(Item.Start, vbLongTime) & vbCrLf & _
"En: " & FormatDateTime(Item.End, vbLongTime) & vbCrLf & _
"Loc: " & Item.Location & vbCrLf & _
"Dtls: " & vbCrLf & Item.Body
Case olContact '40
SafeItem.Body = _
"Contact: " & Item.FullName & vbCrLf & _
"Phone: " & Item.BusinessTelephoneNumber & vbCrLf & _
"Contact Details: " & vbCrLf & Item.Body
Case olMail '43
SafeItem.Body = _
"Due: " & FormatDateTime(Item.FlagDueBy, vbLongTime) &
vbCrLf & _
"Dtls: " & vbCrLf & Item.Body
Case olTask '48
SafeItem.Body = _
"St: " & FormatDateTime(Item.StartDate, vbLongTime) & vbCrLf
& _
"En: " & FormatDateTime(Item.DueDate, vbLongTime) & vbCrLf &
_
"Details: " & vbCrLf & Item.Body
End Select

' send the message
If Item.Class = "26" Then
' SafeItem.Send
End If
End Sub
----
Private Sub Application_Startup()
Set objReminders = Application.Reminders
End Sub
----
Private Sub objReminders_ReminderFire(ByVal ReminderObject As
Reminder)
Dim SafeItem, oItem
Dim objRem As Outlook.Reminder
Set olApp = New Outlook.Application
Set objReminders = Application.Reminders
'whatever
'MsgBox "A reminder has been fired from the collection."
' ReminderObject.Item.Display uncomment to show detail
Dim DismissFlag
'Dim objRem As Reminder
'Set olApp = Outlook.Application

DismissFlag = True
' Wait a few seconds to hit snooze or quit
PauseTime = 1 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
'
' Pause to give time to dismiss the reminder
' I now know that this will not work b/c it won't let dismiss
' i will figure how to use reminderdismiss to acomplish later.

For i = objReminders.Count To 1 Step -1
If objReminders(i).IsVisible = True Then
Set objRem = olApp.Reminders.Item(i)
s = objRem.Class
Set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create
an instance of Redemption.SafeMailItem
Set oItem = Application.CreateItem(0) 'Create a new message
SafeItem.Item = oItem 'set Item property
SafeItem.Recipients.Add "(e-mail address removed)"
SafeItem.Recipients.ResolveAll
SafeItem.Subject = "Reminder: " & objRem.Subject
SafeItem.Body = _
"St: " & FormatDateTime(objRem.Start, vbLongTime) & vbCrLf &
_
"En: " & FormatDateTime(objRem.Duration, vbLongTime) &
vbCrLf & _
"Loc: " & objReminders(i).Location & vbCrLf & _
"Dtls: " & vbCrLf & objReminders(i).Caption
'MsgBox "send chris cell reminder visible."
Call Send_Chris_CellPhone
End If
Next
'End If
Set olApp = Nothing
Set objReminders = Nothing
Set objRem = Nothing
End Sub
 
K

Ken Slovak - [MVP - Outlook]

You most likely don't need to do everything you are doing, it seems somewhat
redundant to handle ReminderFire and Application.Reminder and in Outlook VBA
code you never need to instantiate an Outlook.Application object, that is
intrinsic in the Application object.

What you are getting is a Reminder object. To get the underlying item that
fired the reminder you need to use Reminder.Item. Application.Reminder gives
you that Item without explicitly having to get it, but ReminderFire provides
the Reminder object and you need to use Reminder.Item to get the object you
are really looking for.

Make sense?
 

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