Search code examples
outlookoutlook-addin

Outlook VSTO: Cancel out of Send event for appointment items


I am creating an Outlook VSTO that allows users to enter information in an additional form-region on the New appointment form. When sending the appointment I would like to capture the 'Send' event and perform some checks on the data the user provided. When this data is OK the appointment can be send, otherwise the Send action must be cancelled.

My code is like this:

Dim apptItem as Outlook.AppointmentItem

Private Sub Test_FormRegionShowing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing
        apptItem = OutlookItem
        AddHandler apptItem.Send, AddressOf sendAppt
End Sub



    Private Sub sendAppt()
        If some_test = False then

              else
                Cancel=True
        End If
End Sub

How do I pass the event arguments to my SendAppt function so that I can cancel out of the routine and prevent the meeting from being send?


Solution

  • Well, the answer was rather simple and the solution is like this:

    Private sub SendAppt (ByRef Cancel as Boolean)
        If [some test] = False Then
            Cancel = True
        End If
    End Sub
    

    This will cancel out of the send routine and holds the meeting item from being send.