ItemChange Event

Microsoft Outlook Visual Basic

ItemChange Event

       

Occurs when an item in the specified collection is changed. This event is not available in VBScript.

Sub object_ItemChange(ByVal Item As Object)

object   An expression that evaluates to one of the objects in the Applies To list.

Item   Required. The item that was changed.

Example

This example uses the Start property of the AppointmentItem object to determine if the appointment starts after normal business hours. If it does, and if the Sensitivity property of the AppointmentItem object is not already set to olPrivate, the example offers to mark the appointment as private.

Dim myOlApp As New Outlook.Application
Public WithEvents myOlItems As Outlook.Items

Public Sub Initialize_handler()
    Set myOlItems = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Items
End Sub

Private Sub myOlItems_ItemChange(ByVal Item As Object)
    If Format(Item.Start, "h") >= "17" And Item.Sensitivity <> olPrivate Then
        Prompt = "Appointment occurs after hours. Mark it private?"
        If MsgBox(Prompt, vbYesNo + vbQuestion) = vbYes Then
            Item.Sensitivity = olPrivate
            Item.Display
        End If
    End If
End Sub