Exchange 2010 and Outlook 2003: ItemAdd event does not fire in online mode No ratings yet.

0

A known issue that keeps cropping up is one that occurs when running Outlook 2003 in online mode against Exchange 2010.  If you subscribe to events on an Items collection (e.g. you want to receive an ItemAdd event anytime an item is added to a folder), you will find that you do not actually receive the events when running in online mode.

The quickest fix for this is to change to cached mode – events are handled in a different way in cached mode, and the problem doesn’t occur.

Of course, it isn’t always possible to use cached mode.  There is another workaround that can be used quite successfully though.  Consider the following code (which can be tested in Outlook, just paste it into the ThisOutlookSession module of the VBA Editor):

Private WithEvents ReceivedItems As Items
Private WithEvents SentItems As Items

Private Sub Application_Startup()
    Set ReceivedItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    Set SentItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub ReceivedItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Item.Subject = "ItemAdd fired: " & Item.Subject
    Item.Save
End Sub

Private Sub SentItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Item.Subject = "ItemAdd fired: " & Item.Subject
    Item.Save
End Sub

The above code demonstrates the issue, and will not work in Outlook 2003 in online mode against Exchange 2010.  However, the following code does work:

Private WithEvents ReceivedItems As Items
Private WithEvents SentItems As Items

Private Sub Application_Startup()
    Set ReceivedItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    Set SentItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
    If MsgBox("ItemAdd hooks set. Implement fix?", vbInformation + vbYesNo, "Event Test Initialised") = vbYes Then
        ' Events may not fire against Exchange 2010
        On Error Resume Next
        ReceivedItems.GetFirst
        SentItems.GetFirst
        Err.Clear
    End If
End Sub

Private Sub ReceivedItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Item.Subject = "ItemAdd fired: " & Item.Subject
    Item.Save
End Sub

Private Sub SentItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Item.Subject = "ItemAdd fired: " & Item.Subject
    Item.Save
End Sub

 The fix is to call GetFirst on the folder you are subscribing to.  While the issue does seem to be due to a change in Exchange 2010, it is not likely to be fixed in Exchange as the workaround above is very easy to implement.  Later versions of Outlook subscribe to folders in a different way, and they are not affected by this issue.

0

Please rate this

Leave a Reply

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