Trapping delete event for all folders

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
 
K

Ken Slovak - [MVP - Outlook]

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.
 
L

Lars Moastuen

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top