BeforeDelete Event

Microsoft Outlook Visual Basic

BeforeDelete Event

       

Occurs before an item is deleted.

Sub expression_ BeforeDelete(ByVal Item As Object, Cancel As Boolean)

expression   An object in the Applies To list declared with events in a class module.

Item  Required Object.The item being deleted.

Cancel   Required Boolean. False when the event occurs. If the event procedure sets this argument to True, the operation is not completed and the item is not deleted.

Remarks

In order for this event to fire when a mail message, distribution list, journal entry, task, contact or post  are deleted through an action, an Inspector must be open.

The event occurs each time an item is deleted.

Example

The following example prompts the user regarding whether to delete the specified item. If the user clicks No, the item will not be deleted. If the user clicks Yes, the item will be deleted and a message will be displayed to the user.


Private Sub objMail_BeforeDelete(ByVal Item As Object, Cancel As Boolean)
'Prompts the user before deleting an item

    Dim strPrompt As String
    'Prompt the user for a response
    strPrompt = "Are you sure you want to delete the item?"
    If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbNo Then
        'Don't delete the item
        Cancel = True
    Else
        MsgBox ("Item Deleted")
        'Delete the item
        Cancel = False
    End If

End Sub