AppointmentItem.BeforeDelete Event

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

I am trying to create code in VBA to trigger an event anytime that an
AppointmentItem in my calendar is deleted so that I can do some processing.
The BeforeDelete event seems to be the one, but I am having trouble figuring
out exactly how I would link the event to the the Calendar. In VBA, the only
events that I see are the ones assocated with the Application. How do I
implement the events for stuff happening in the Calendar?

Thanks!

Kevin
 
The event you should use is Folder.BeforeItemMove; see its topic in Help or
in the Outlook Developer Reference at
http://msdn.microsoft.com/en-us/library/bb147840.aspx. To see that event in
action, put the following code in the built-in ThisOutlookSession module and
either restart Outlook or run the Application_Startup procedure:

Dim WithEvents objCalFolder As Outlook.Folder
Dim objDelFolder As Outlook.Folder

Private Sub Application_Startup()
Set objCalFolder =
Application.Session.GetDefaultFolder(olFolderCalendar)
Set objDelFolder =
Application.Session.GetDefaultFolder(olFolderDeletedItems)
End Sub

Private Sub objCalFolder_BeforeItemMove(ByVal Item As Object, ByVal
MoveTo As MAPIFolder, Cancel As Boolean)
If MoveTo Is Nothing Then
Debug.Print Item.Subject & " was hard deleted"
ElseIf MoveTo = objDelFolder Then
Debug.Print Item.Subject & " was moved to Deleted Items"
End If
End Sub
 
Sorry about the bad line wrapping. Those Set statements can have an
underscore
line break in them to make them display better in this newsgroup:

Set objCalFolder = _
Application.Session.GetDefaultFolder(olFolderCalendar)
Set objDelFolder = _
Application.Session.GetDefaultFolder(olFolderDeletedItems)
 
Back
Top