none
Outlook 2016 produces an extra ItemChange event after an appointment is created RRS feed

  • Question

  • Hello,

    Consider this VBA class:

    Option Explicit
    
    Dim WithEvents ItemsObj As Outlook.Items
    
    Public Sub Initialize(someItems As Outlook.Items)
        Set ItemsObj = someItems
        Debug.Print DateTime.Now, "clsOutlookItems", "Initialize"
    End Sub
    
    Public Sub Finalize()
        Set ItemsObj = Nothing
        Debug.Print DateTime.Now, "clsOutlookItems", "Finalize"
    End Sub
    
    Private Sub ItemsObj_ItemAdd(ByVal Item As Object)
        Debug.Print DateTime.Now, "clsOutlookItems", "ItemsObj_ItemAdd", Item.Subject
    End Sub
    
    Private Sub ItemsObj_ItemChange(ByVal Item As Object)
        Debug.Print DateTime.Now, "clsOutlookItems", "ItemsObj_ItemChange", Item.Subject
    End Sub

    I connect it to events of the Items collection of the Calendar folder using these code lines:

    Dim itms As clsOutlookItems
    
    Sub StartTest()
        Set itms = New clsOutlookItems
        itms.Initialize Application.Session.GetDefaultFolder(olFolderCalendar).Items
    End Sub
    
    Sub StopTest()
        itms.Finalize
        Set itms = Nothing
    End Sub

    The remaining ingredient is an appointment that I create using the method below; actually, I see the same issue if I create an appointment in the Outlook UI:

    Sub CreateAppt()
        Dim appt As Outlook.AppointmentItem
        Set appt = Application.Session.GetDefaultFolder(olFolderCalendar).Items.Add(olAppointmentItem)
        appt.Subject = "testtest"
        appt.Start = DateAdd("d", 1, Now)
        appt.End = DateAdd("d", 2, Now)
        appt.Save
        Set appt = Nothing
    End Sub

    Initializing the class, creating the appointment and waiting for some time reveals that Outlook updates some appointments behind the scenes. Below is the debug output I received after performing  these steps. The "Test {NNN}" appointments mentioned below are *some* of the test appointments created yesterday. That is, it looks like in 6 seconds after the testtest appointment was created, Outlook decided to update it as well as some of the other appointments. Needless to say that a real add-in decides that the appointment is updated by the user.

    6/26/2018 3:28:44 PM        clsOutlookItems             Initialize
    6/26/2018 3:28:54 PM        clsOutlookItems             ItemsObj_ItemAdd            testtest
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 387
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 388
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 389
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 390
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 391
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 392
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 393
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 394
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 395
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 396
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 397
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 398
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 399
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         Test 400
    6/26/2018 3:29:01 PM        clsOutlookItems             ItemsObj_ItemChange         testtest

    I reproduce this issue using Outlook 2016 32bit version 1807 build 10313.20013 Click-to-Run. The account is connected to Exchange Online, Cached Mode. 

    I don't reproduce this issue when using Outlook 2016 32bit version 1805 build 9330.2124 Click-to-Run. The account used in this case is a PST connected to GMail via POP and SMTP.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.


    • Edited by Andrei Smolin Tuesday, June 26, 2018 1:57 PM replaced ItemAdd-->ItemChange in the subject
    Tuesday, June 26, 2018 12:55 PM

Answers

  • I can see only one ItemAdd event above. ItemChange event is expected to fire multiple times - Exchange likes to update appointments quote often, especially immediately after they were created.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Andrei Smolin Tuesday, June 26, 2018 2:12 PM
    Tuesday, June 26, 2018 1:53 PM
  • There is no way to find that out. You really need to test if the properties you need changed.

    Even if the edit was done by an end user, does it matter if they modify a property you don't care about?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Andrei Smolin Tuesday, June 26, 2018 2:05 PM
    Tuesday, June 26, 2018 2:02 PM
  • You might also want to keep in mind that ItemAdd *will* fire if a meeting update is received - Outlook deletes the old appointment and creates a new one with the same appointment id.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Andrei Smolin Tuesday, June 26, 2018 2:12 PM
    Tuesday, June 26, 2018 2:09 PM

All replies

  • I can see only one ItemAdd event above. ItemChange event is expected to fire multiple times - Exchange likes to update appointments quote often, especially immediately after they were created.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Andrei Smolin Tuesday, June 26, 2018 2:12 PM
    Tuesday, June 26, 2018 1:53 PM
  • Hello Dmitry,

    Thank you for your response. Unfortunately, I made a mistake in the subject line: this is an extra ItemChange I'm after. Do you know how to find out if such an event is raised by the user action, not  by Exchange


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Tuesday, June 26, 2018 1:56 PM
  • There is no way to find that out. You really need to test if the properties you need changed.

    Even if the edit was done by an end user, does it matter if they modify a property you don't care about?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Andrei Smolin Tuesday, June 26, 2018 2:05 PM
    Tuesday, June 26, 2018 2:02 PM
  • Thank you. I'll consider changing the code as this approach requires storing some info about the appointment in order to compare it with the current state.

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Tuesday, June 26, 2018 2:05 PM
  • You might also want to keep in mind that ItemAdd *will* fire if a meeting update is received - Outlook deletes the old appointment and creates a new one with the same appointment id.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Andrei Smolin Tuesday, June 26, 2018 2:12 PM
    Tuesday, June 26, 2018 2:09 PM
  • Oh! Thank you very much!

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Tuesday, June 26, 2018 2:11 PM