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.
- 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”
- 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”]