Trapping delete event for all folders

  • Thread starter Thread starter Lars Moastuen
  • Start date Start date
L

Lars Moastuen

I have a macro (in ThisOutlookSession) to trap a delete mail-event.
This works fine, but only for one folder (the inbox that is)... What I
want is a event-trap that traps all delete mail-events. I guess I have
to do some kind of recurssion using
Application.GetNamespace("MAPI").Folders, but how do I add events to
these sub-folders dynamiclly?

My code is as follows:
---

Private WithEvents olInboxItems As Items

Private Sub Application_Startup()
Call Initialize_handler
End Sub

Private Sub Initialize_handler()
Set olInboxItems =
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub olInboxItems_ItemRemove()
MsgBox 'Do something'
End Sub
 
The best way to do what you want is to set up a class module that declares
an Items collection WithEvents. Then instantiate that Items collection when
you instantiate the class module. Handle the events you want in the code in
the class module. Add each class module to a collection to keep it
persistent and you can handle the Items.ItemRemove event for any Items
collection you place in the collection.

That's a pretty useless event however since it only fires after the user has
deleted the item and doesn't provide a handle to the item that was deleted.
If the user just deletes an item it would be added to Deleted Items, where
you could trap the ItemAdd event for that Items collection. If the user hard
deletes an item (Shift+Delete) or code hard deletes an item (CDO 1.21,
Extended MAPI or Redemption) then you don't even get the ItemAdd event on
the Deleted Items folder since the item never gets there.
 
Ok thanks alot =)

I know the event isn't really good, but I don't really need to get
notification before the item is deleted, since what I'm using this for
is an automatic purge deleted messages (IMAP) on deletion =)

Lars Moastuen

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top