How to Delete recurring appointments using CDO

Hi, I work with Microsoft PSS Messaging Team. Thought of sharing few things which I learned in my troubleshooting. This is one of them!!

How to Delete recurring appointments using CDO.
Code to delete appointment is generally follwed like this:

For Each oMsg in oMsgCol
iCount = iCount + 1
If Instr(oMsg.Sender.Name, "/OU") > 0 Then 'Checking if the email address is no more in use. Generally used for 
people who left the organization and email account is being deleted.
Wscript.Echo iCount & " - " & oMsg.StartTime & ";" & oMsg.EndTime & ";" & oMsg.Organizer & ";" & oMsg.Subject
oMsg.Delete
iDeleted = iDeleted + 1
End If
Next

Above code block would fail in case of recurring appointments. Because recurring appointments are linked with master appointment and correct way for deleting recurring appointment would be through master appointment.

A code block would look like below

If oMsg.IsRecurring Then
   Set MasterAppt = oMsg.GetRecurrencePattern.Parent 'Get the parent Appointment
   MasterAppt.ClearRecurrencePattern
   MasterAppt.Update
   MasterAppt.Delete
End If
Set MasterAppt = Nothing 'Set the master appointment to nothing
'Cleanup
oMsg.Delete
Set oMsg = Nothing

Looking at the code above we could see that we need to actually clear the recurrence pattern first before deleting the recurring appointment. IsRecurring property returns whether the appointment is recurring or not.

A complete code block would look like below:

For Each oMsg in oMsgCol
   iCount = iCount + 1
   If Instr(oMsg.Sender.Name, "/OU") > 0 Then
      Wscript.Echo iCount & " - " & oMsg.StartTime & ";" & oMsg.EndTime & ";" & oMsg.Organizer & ";" & oMsg.Subject
      If oMsg.IsRecurring Then
         Set MasterAppt = oMsg.GetRecurrencePattern.Parent 'Get the parent Appointment
         MasterAppt.ClearRecurrencePattern
         MasterAppt.Update
         MasterAppt.Delete
     End If
   Set MasterAppt = Nothing 'Set the master appointment to nothing
   oMsg.Delete
   iDeleted = iDeleted + 1
   set oMsg=Nothing
   set MasterAppt = Nothing
End If
Next

- Hope this helps somebody somewhere!!

-Sachin Sancheti
you are never given a wish without giving power to fulfill it.!!!