How To VC: Detect Deleted Appointments in a Recurring Series with Outlook Object Model (260854)



The information in this article applies to:

  • Microsoft Outlook 2000
  • Microsoft Outlook 98

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("Outlook.Application");
_NameSpacePtr pMAPI = spApp->GetNamespace("MAPI");
pMAPI->Logon();<BR/>
// Get the calendar folder.
MAPIFolderPtr spFolder = pMAPI->GetDefaultFolder(olFolderCalendar);
_ItemsPtr spItems = spFolder->GetItems();
k = sprintf(s, "Item Count: %d\n", spItems->Count);
OutputDebugString(s);
spItems->Sort("[Start]");
spItems->IncludeRecurrences = true;<BR/>
// Call Find to quickly check for the existence of an appointment.
spAppointment = spItems->Find("[Start] = ""01/13/2000 10:00""");
if (spAppointment == NULL) {
   OutputDebugString("Find: Occurance has been deleted?");
}
// 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("\n");
         if (spAppointment->IsRecurring == TRUE) {
	    OutputDebugString(" Recurring Appointment");
	    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(" Deleted");
	          else
		     OutputDebugString(" Not Deleted");
	          spException = NULL;
	       } // for loop j
	    } // exceptions count > 0
 	    spExceptions = NULL;
	    spRecurrence = NULL;
         } //If recurring...
         spAppointment->Close(olDiscard);
      } // is null
      else {
         OutputDebugString("NULL Appointment\n");
      } // 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;
)
}
				

REFERENCES

For information on how to work with Outlook Object Model in a Visual C++ project, see the following article in the Microsoft Knowledge Base:

259298 How To Use Microsoft Outlook Object Model From Visual C++ Through an #IMPORT Statement


Modification Type:MinorLast Reviewed:7/15/2004
Keywords:kbhowto kbMsg kbOutlookObj KB260854