Microsoft KB Archive/260854

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

Article ID: 260854

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 Q260854



SUMMARY
This article demonstrates how to use Microsoft Visual C++ 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. void IsApptDeleted { _AppointmentItemPtr spAppointment; RecurrencePatternPtr spRecurrence; ExceptionsPtr spExceptions; ExceptionPtr spException; char s[200]; int k;

_ApplicationPtr spApp(&quot;Outlook.Application&quot;); _NameSpacePtr pMAPI = spApp->GetNamespace(&quot;MAPI&quot;); pMAPI->Logon; // Get the calendar folder. MAPIFolderPtr spFolder = pMAPI->GetDefaultFolder(olFolderCalendar); _ItemsPtr spItems = spFolder->GetItems; k = sprintf(s, &quot;Item Count: %d\n&quot;, spItems->Count); OutputDebugString(s); spItems->Sort(&quot;[Start]&quot;); spItems->IncludeRecurrences = true; // Call Find to quickly check for the existence of an appointment. spAppointment = spItems->Find(&quot;[Start] = &quot;&quot;01/13/2000 10:00&quot;&quot;&quot;); if (spAppointment == NULL) { OutputDebugString(&quot;Find: Occurance has been deleted?&quot;); } // Iterate through all the appointments checking for deleted occurrences. if (spItems->Count > 0) { for (long i = 1; i <= spItems->Count; ++i) { spAppointment = spItems->Item(i); if (spAppointment != NULL) { OutputDebugString(spAppointment->Subject); OutputDebugString(&quot;\n&quot;); if (spAppointment->IsRecurring == TRUE) { OutputDebugString(&quot; Recurring Appointment&quot;); spRecurrence = spAppointment->GetRecurrencePattern; // Get Exceptions collection of RecurrencePattern object. spExceptions = spRecurrence->Exceptions; if (spExceptions->Count > 0) { for (long j = 1; j <= spExceptions->Count; ++j) { spException = spExceptions->Item(j); if (spException->Deleted == TRUE) OutputDebugString(&quot; Deleted&quot;); else OutputDebugString(&quot; Not Deleted&quot;); spException = NULL; } // for loop j       } // exceptions count > 0 spExceptions = NULL; spRecurrence = NULL; } //If recurring... spAppointment->Close(olDiscard); } // is null else { OutputDebugString(&quot;NULL Appointment\n&quot;); } // is null spAppointment = NULL; // Set a limit to avoid recurring appointments with no end date. if (i > 50000) break; } // for loop } // count > 0 spItems = NULL; spFolder = NULL; pMAPI->Logoff; pMAPI = NULL; spApp = NULL; ) }

