Microsoft KB Archive/260896

= How To VB: Detect Deleted Appointments in a Recurring Series with Outlook Object Model =

Article ID: 260896

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Outlook 98 Standard Edition

-



This article was previously published under Q260896



SUMMARY
This article demonstrates how to use Microsoft Visual Basic with Microsoft Outlook Object Model to programmatically detect a deleted appointment occurrence in a recurring series.



MORE INFORMATION
The following sample code works with recurring appointments by using the RecurrencePattern object and the Exceptions collection. Private Sub IsApptDeleted Dim spApp As Outlook.Application Dim spMAPI As NameSpace Dim spFolder As MAPIFolder Dim spItems As Items Dim spAppointment As AppointmentItem Dim spRecurrence As RecurrencePattern Dim spExceptions As Exceptions Dim spException As Exception Dim s As String Dim k As Integer Dim i As Long, j As Long

Set spApp = CreateObject(&quot;Outlook.Application&quot;) Set spMAPI = spApp.GetNamespace(&quot;MAPI&quot;) spMAPI.Logon ' Get the calendar folder. Set spFolder = spMAPI.GetDefaultFolder(olFolderCalendar) Set spItems = spFolder.Items Debug.Print &quot;Item Count: &quot; & spItems.Count spItems.Sort(&quot;[Start]&quot;) spItems.IncludeRecurrences = True ' Call Find to quickly check for the existence of an appointment. Set spAppointment = spItems.Find(&quot;[Start] = &quot;&quot;01/13/2000 10:00&quot;&quot;&quot;) If spAppointment Is Nothing Then Debug.Print &quot;Find: Occurrence has been deleted?&quot; End If ' Iterate through all the appointments checking for deleted occurrences. If spItems.Count > 0 then For i = 1 To spItems.Count Set spAppointment = spItems.Item(i) If Not (spAppointment Is Nothing) Then Debug.Print spAppointment.Subject If spAppointment.IsRecurring = True Then Debug.Print &quot; Recurring Appointment&quot; Set spRecurrence = spAppointment.GetRecurrencePattern 'Get Exceptions collection of RecurrencePattern object. Set spExceptions = spRecurrence.Exceptions If spExceptions.Count > 0 Then For j = 1 To spExceptions.Count Set spException = spExceptions.Item(j) If spException.Deleted = True Then Debug.Print &quot; Deleted&quot; Else Debug.Print &quot; Not Deleted&quot; End If             Set spException = Nothing Next j       End If 'exceptions count > 0 Set spExceptions = Nothing Set spRecurrence = Nothing End If 'If recurring... spAppointment.Close(olDiscard) Else ' is Null Debug.Print &quot;NULL Appointment&quot; End If ' is null Set spAppointment = Nothing 'Set a limit to avoid recurring appointments with no end date. If i > 50000 Then Exit For End If  Next i End If 'count > 0 Set spItems = Nothing Set spFolder = Nothing spMAPI.Logoff Set spMAPI = Nothing Set spApp = Nothing

End Sub

Keywords: kbhowto kboutlookobj kbmsg KB260896

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.