none
Finding the appropriate AppointmentItem of a Reminder RRS feed

  • Question

  • Hello,

    For an Outlook Add In I want to catch certain Reminders to make sure they are not shown.

    To check if a certain Reminder should be shown I need to find the appropriate AppointmentItem, but only if it is a Reminder for an Appointment of course.

    I'm using the Application.Reminders.BeforeReminderShow to make sure my function gets called before the Reminder Window shows.

    How I wanted to check to Reminders:

    foreach (Reminder reminder in Application.Reminders) { var currentAppointment = reminder.Item as AppointmentItem; if (currentAppointment == null) continue;

    // Code that determines if the reminder should be shown. }

    But this code never works, the type of every reminder is System.__ComObject.

    Even when I try to check the reminder.Parent() with different reminders, it always says it's System.__ComObject.

    Anyone know how I can get the appropriate AppointmentItem of a Reminder?

    Thanks in advance,

    Frenk


    • Edited by IAmFrenk Tuesday, December 5, 2017 11:11 AM Grammar
    Tuesday, December 5, 2017 11:08 AM

Answers

  • Hello,

    Reminders.ReminderFire Event (Outlook) occurs before the reminder is executed.

    You could handle the event to get related appointment and then in the Reminders.BeforeReminderShow Event (Outlook) cancel it if it is the certain appointment you find. 

    The events work fine when i write in VBA, however the same event handler would not fire in VSTO add-ins. 

    >> this code never works
    Would the event fire in your add-ins?

    Public WithEvents objReminders As Outlook.Reminders
    Dim bool As Boolean
    
    Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    MsgBox "objReminders_ReminderFire"
    If ReminderObject.Item.Subject = "test11" Then
    bool = True
    End If
    End Sub
    
    Private Sub objReminders_BeforeReminderShow(Cancel As Boolean)
    MsgBox "objReminders_BeforeReminderShow"
    If bool Then
    MsgBox "the reminder has been cancelled"
    Cancel = True
    End If
    End Sub
    

       public Boolean isDis=false;
            private void Reminders_ReminderFire(Outlook.Reminder ReminderObject)
            {
                if (ReminderObject.Item.Subject=="test")
                {
                    isDis = true;
                } 
            }
    
            private void Reminders_BeforeReminderShow(ref bool Cancel)
            {
                if (isDis)
                {
                    Cancel = true;
                    MessageBox.Show("Has cancelled");
                }
               
            }

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 6, 2017 6:22 AM
    Moderator

All replies

  • Hello,

    Reminders.ReminderFire Event (Outlook) occurs before the reminder is executed.

    You could handle the event to get related appointment and then in the Reminders.BeforeReminderShow Event (Outlook) cancel it if it is the certain appointment you find. 

    The events work fine when i write in VBA, however the same event handler would not fire in VSTO add-ins. 

    >> this code never works
    Would the event fire in your add-ins?

    Public WithEvents objReminders As Outlook.Reminders
    Dim bool As Boolean
    
    Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    MsgBox "objReminders_ReminderFire"
    If ReminderObject.Item.Subject = "test11" Then
    bool = True
    End If
    End Sub
    
    Private Sub objReminders_BeforeReminderShow(Cancel As Boolean)
    MsgBox "objReminders_BeforeReminderShow"
    If bool Then
    MsgBox "the reminder has been cancelled"
    Cancel = True
    End If
    End Sub
    

       public Boolean isDis=false;
            private void Reminders_ReminderFire(Outlook.Reminder ReminderObject)
            {
                if (ReminderObject.Item.Subject=="test")
                {
                    isDis = true;
                } 
            }
    
            private void Reminders_BeforeReminderShow(ref bool Cancel)
            {
                if (isDis)
                {
                    Cancel = true;
                    MessageBox.Show("Has cancelled");
                }
               
            }

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 6, 2017 6:22 AM
    Moderator
  • Hi Celeste,

    Thanks for your reply.

    Can't believe I missed the Reminders.ReminderFire event, it's exactly what I needed!

    Now I only have to use this function:

    private void FilterReminders(Reminder reminder)
    {
       if (!(reminder.Item is AppointmentItem currentAppointment)) return;
       
       // Determine if Appointment's Reminder should be shown, if so: return
    
       currentAppointment.ReminderSet = false;
       currentAppointment.Save();
    }

    Cheers,

    Frenk

    Wednesday, December 6, 2017 8:44 AM