reminder question

  • Thread starter Thread starter soworl
  • Start date Start date
S

soworl

is there any way to dismiss when Application_Reminder is called.

I need to excute some code when reminder called, then I'd like to dismiss
that reminder without clicking the dismiss button.

when below code is running, the reminder cannot dismiss coz reminder is not
visable. dismiss only can work it's visible.

How can I solve this problem?

Help me,
soworl

my code 1 ==============================
Dim ReminderClass As New Class1

Private Sub Application_Startup()
ReminderClass.init
End Sub

Private Sub Application_Reminder(ByVal Item As Object)
'DoSomething
ReminderClass.ReminderDismiss Item.Subject
End Sub

class1 ==============================
Private WithEvents myolapp As Outlook.Application
Private WithEvents colReminders As Reminders
Sub Class_Terminate()
Call DeRefExplorers
End Sub
Public Sub init()
Set myolapp = Outlook.Application
Set colReminders = myolapp.Reminders
End Sub
Public Sub DeRefExplorers()
Set myolapp = Nothing
Set colReminders = Nothing
End Sub
Public Sub ReminderDismiss(ByVal sCaption As String)
If colReminders.Count <> 0 Then
For i = colReminders.Count To 1 Step -1
If Len(colReminders(i).Caption) > 0 Then
If colReminders(i).Caption = sCaption Then
If colReminders(i).IsVisible = True Then
colReminders(i).Dismiss
End If
End If
End If
Next
End If
End Sub
 
If you have a current version of Outlook, you'll have more options if you use events for the Reminders collection rather than Application.Reminder.
 
Hi Sue,

What do you mean the current version of outlook, 2007?

I'm using 2003.
Does that mean there is no way to solve this problem?

Please, advise me.

thanks,
soworl
 
Outlook 2003 and 2007 are the current versions of Outlook, those still within their support cycle.

The object browser is your friend: Press ALt+F11 to open the VBA environment in Outlook, then press F2. Switch from <All Libraries> to Outlook to browse all Outlook objects and their properties, methods, and events. Select any object or member, such as Reminders.ReminderFire then press F1 to see its Help topic.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Now, I solve one step using below code.
but still have some questions.

Is it possible to know the Appointment.EndTime using Reminder or Reminders?
I only can find below property in Reminder.
Application Property
Caption Property
Class Property
IsVisible Property
Item Property
NextReminderDate Property
OriginalReminderDate Property
Parent Property
Session Property

if there is no endtime property in Reminder, can I make own reminder object?

Or Is there any way using other object?
give me some idea.

thanks,
soworl

===============================================
Private Sub colReminders_BeforeReminderShow(Cancel As Boolean)
Dim lngAns As Long
Dim objRem As Reminder

If colReminders.Count <> 0 Then
For i = colReminders.Count To 1 Step -1
If Len(colReminders(i).Caption) > 0 Then
Set objRem = colReminders.Item(i)
' Interval = DateDiff("s", Now(), objRem.End) 'seconds
->dosenot work
' MsgBox "interval=" & Interval
colReminders.Remove (i)
End If
Next
End If
Cancel = True
End Sub
===============================================
 
Item will return the item that fired the reminder, whether it's a message, appointment, task, or contact.You can then use whatever properties you need from that item.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
as I understand,

Item return the reminder object when BeforeReminderShow is call, not
appointment object.
that's why my code (objRem.End) causes error.


I can get the appointment item from the Application_Reminder
I can get the reminder item from the BeforeReminderShow
Is it correct?

I need to use BeforeReminderShow event, not Application_Reminder.
Is there any way to get Appointment item from BeforeReminderShow?

right now, I'm looking into the Session to solve this problem.

Thanks,
soworl
 
I would use ReminderFire, which will give you a Reminder object and thus the Item firing the object. You can Snooze or Dismiss the reminder if you don't want it to fire. This sample (adapted from Listing 11.22 in my latest book) shows only the reminders for items marked as Important and snoozes any others for an hour:

Private Sub m_colReminders_ReminderFire _
(ByVal ReminderObject As Reminder)
On Error Resume Next
Dim objItem As Object
Set objItem = ReminderObject.Item
If objItem.Importance <> olImportanceHigh Then
ReminderObject.Snooze 60
End If
Set objItem = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Thanks Sue,
it is really helpful.

I works like that I want.

I have another problem. can you advise me?
thing is,
Here is the sinario.
When Reminder Fires,
(1) get the Item.End time,
(2) Dismiss Reminder,
(3) wait by End time, (using Win32 API,
http://www.vboffice.net/sample.html?lang=en&mnu=2&smp=4&cmd=showitem)
(4) and then set the appointment color label.

Now (1)~(3) is done.
but, (4) has problem.
the funcion which is called from the timer dose not know that item.
Is there any way to pass this item object to Timer?

Please, Advice me.
Thanks a lot ^_^

Here is my code.
=ThisOutlookSession START===================================
Dim ReminderClass As New Class1
Private Sub Application_Startup()
ReminderClass.init
End Sub
Private Sub Application_Quit()
DisableTimer
End Sub
Public Sub Initialize_handler()

End Sub
=ThisOutlookSession END=====================================
=Class1 START===========================================
Private WithEvents myolapp As Outlook.Application
Private WithEvents colReminders As Reminders

Sub Class_Terminate()
Call DeRefExplorers
End Sub

Public Sub init()
Set myolapp = Outlook.Application
Set colReminders = myolapp.Reminders
End Sub

Public Sub DeRefExplorers()
Set myolapp = Nothing
Set colReminders = Nothing
End Sub

Private Sub colReminders_ReminderFire(ByVal ReminderObject As Reminder)
Dim objItem As Object
Set objItem = ReminderObject.Item

interval = DateDiff("s", Now(), objItem.End) 'seconds

ReminderObject.Dismiss

EnableTimer interval * 1000, Me

Set objItem = Nothing
End Sub

Public Sub Timer()
MsgBox "Called from the timer"
'SetApptColorLabel(item,1)
DisableTimer
End Sub

Public Sub SetApptColorLabel(objAppt As Outlook.AppointmentItem, _
intColor As Integer)
' requires reference to CDO 1.21 Library
' adapted from sample code by Randy Byrne
' intColor corresponds to the ordinal value of the color label
'1=Important, 2=Business, etc.
Const CdoPropSetID1 = "0220060000000000C000000000000046"
Const CdoAppt_Colors = "0x8214"
Dim objCDO As MAPI.Session
Dim objMsg As MAPI.Message
Dim colFields As MAPI.Fields
Dim objField As MAPI.Field
Dim strMsg As String
Dim intAns As Integer
On Error Resume Next

Set objCDO = CreateObject("MAPI.Session")
objCDO.Logon "", "", False, False
If Not objAppt.EntryID = "" Then
Set objMsg = objCDO.GetMessage(objAppt.EntryID, _
objAppt.Parent.StoreID)
Set colFields = objMsg.Fields
Set objField = colFields.Item(CdoAppt_Colors, CdoPropSetID1)
If objField Is Nothing Then
Err.Clear
Set objField = colFields.Add(CdoAppt_Colors, vbLong, intColor,
CdoPropSetID1)
Else
objField.Value = intColor
End If
objMsg.Update True, True
Else
strMsg = "You must save the appointment before you add a color
label. " & _
"Do you want to save the appointment now?"
intAns = MsgBox(strMsg, vbYesNo + vbDefaultButton1, "Set Appointment
Color Label")
If intAns = vbYes Then
Call SetApptColorLabel(objAppt, intColor)
End If
End If

Set objMsg = Nothing
Set colFields = Nothing
Set objField = Nothing
objCDO.Logoff
Set objCDO = Nothing
End Sub
=CLASS1 END===========================================

=Modul1 START===========================================
' <Modul: modTimer.bas>
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
=Modul1 END=============================================
 
Any time you need to access an object from procedures in different modules, you can declare a global object variable and instantiate it.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Thanks for quick response.

If there are multiple appointments and the end time dose not have rules
which means NOT FIFO, is it possible to recognize?

for example,
first appointment: starts at 1:00, ends at 1:30 -item1
second appointment : starts at 1:10, ends at 1:20 -item2

Thanks,
soworl
 
For that scenario, you could use a wrapper class to maintain references to multiple appointments. (All the best Outlook add-in samples use wrapper classes.) Or, since you don't need events, you could maintain a collection of just EntryID and time values.

If that doesn't help, I'd suggest you start a new discussion thread, since you've shifted the focus of this one considerably and I'm no expert in WIndows API Timer operations.


--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Back
Top