'RecurrencePattern: range of recurrence - "End after X" vs "End by date"?

I have a VSTO Outlook Add-in and I need to collect all calendar and tasks items with all their properties. This is ok, but the problem come when I use the RecurrencePattern. It works very well and returns almost all properties that I need, except one.

In the 'Range of recurrence' form the user can choose how long to continue his task when he choose on of the tree radio buttons.

  • No end date
  • End after: 3(for example) occurrences
  • End by: some date

The RecurrencePattern have a boolean property only for the first one - No end date.

When the first radio is not marked I need to understand which one of the second or third is marked, but RecurrencePattern does not have a property for them. It returns the number of occurrences and end date, but I need the checked radio button.

I am wondering can I have a event on these radio buttons or can I take their boolean properties in some other way, but I can't find anything about that.

I don't use Ribbon or some other form and I don't need to use it in this case.

My Outlook is 2016 and the .net framework is 4.6.1.

Thanks for any assistance!



Solution 1:[1]

  1. See NoEndDate.

  2. Looks like you are interested in the Occurrences property of the RecurrencePattern class which returns a Long indicating the number of occurrences of the recurrence pattern. This property allows the definition of a recurrence pattern that is only valid for the specified number of subsequent occurrences. For example, you can set this property to 10 for a formal training course that will be held on the next ten Thursday evenings. This property must be coordinated with other properties when setting up a recurrence pattern. If the PatternEndDate property or the Occurrences property is set, the pattern is considered to be finite and the NoEndDate property is False . If neither PatternEndDate nor Occurrences is set, the pattern is considered infinite and NoEndDate is True.

  3. The PatternEndDate property of the RecurrencePattern class returns a Date indicating the end date for the recurrence pattern. This property is optional but must be coordinated with other properties when setting up a recurrence pattern. If this property or the Occurrences property is set, the pattern is considered to be finite, and the NoEndDate property is False . If neither PatternEndDate nor Occurrences is set, the pattern is considered infinite and NoEndDate is True . The Interval property must be set before setting PatternEndDate .

Solution 2:[2]

For some inexplicable reason, Outlook Object Model does not expose that information. You can either parse the recurrence pattern blob yourself (its format is documented, but isn't fun to parse) or you can use Redemption (I am its author) and its RDORecurrencePattern.PatternEndKind property. Assuming a recurring appointment is selected in Outlook:

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set appt = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
  strPattern = "Not recurring"
  if appt.IsRecurring Then
    set pattern = appt.GetRecurrencePattern
    select case pattern.PatternEndKind
      case 0 strPattern = "No end date"  'rekNoEndDate
      case 1 strPattern = "End after X occurrences"  'rekEndAfterOccurrences
      case 2 strPattern = "End by date"  'rekEndByDate
    end select
  End If
  MsgBox strPattern

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev
Solution 2