Catching all changes on an Outlook folder

I found events in microsoft outlook to be unreliable. If a modal dialog box is open (eg. MsgBox or InputBox) or a piece of code takes to long to complete, events in the background will be cancelled.  This class tries to catch the Add and Change events of a folder but will also check, after handling an item, if additional changes have occured and will then handle those subsequentially.

The way it works

Add and Change events are caught, yet after each of these events the folder is checked for additional changes (LastModifiedTime of the items). In case an event was missed outside of the eventhandlers, there is a timer that runs at a specific interval (5 seconds default) that will check for changes anyway. All items that changed will be added to a queue. Just work your way through the queue and you can rest assured you handled all changes.

Using it

  • Create object, set the folder property to the outlook folder you want monitored
  • Optionally set the interval for checking the folder (default is 5 seconds)
  • Create the eventhandler for handling the ‘ItemsAreWaiting’ event raised by this class
  • In the event handler call the GetItemFromQueue function repeatedly until it returns “Nothing”

Notes

  • If you use this class, then do not use the regular outlook events, because you will be handling them twice
  • This class does not differentiate between adding or changing
  • This class is more reliable than Outlook, yet there might be delays in handling items and there will be a PERFORMANCE PENALTY FOR CHECKING ALL ITEMS IN THE FOLDER AT EACH EVENT

The code can be found here on OutlookCode.com.

[ad name=”468×60 Banner”]

Be Sociable, Share!

2 thoughts on “Catching all changes on an Outlook folder

  1. I ran across your code on outlookcode.com and it does exactly what I need to do, yet I need to be able to have recursion so that it can handle not only the folder but all sub-folders of that root folder as well. Can you provide any type of guidance on achieving this?

  2. hmmmm it’s been ages since I wrote that stuff. My first guess would be to check whether the Outlook folks actually implemented a better event mechanism that no longer requires my code.

    second; you can create an object for each underlying folder as well. In that case, you probably should modify the event, to also pass the object itself as a parameter. This will not catch any changes in the folder structure, that would require some additional code, but only if you have a requirement to do so.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Subscribe without commenting