MailItem.BeforeDelete Event
Outlook Developer Reference |
Occurs before an item (which is an instance of the parent object) is deleted.
Syntax
expression.BeforeDelete(Item, Cancel)
expression A variable that represents a MailItem object.
Parameters
Name | Required/Optional | Data Type | Description |
---|---|---|---|
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 an e-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 Visual Basic for Applications (VBA) example prompts the user regarding whether to delete the item currently open. For this example to run, you need to have an open e-mail item that can be deleted. If you click No, the item will not be deleted. If this event is canceled, Microsoft Outlook displays an error message. Therefore, you need to capture this event in your code. One way to do this is shown below. The sample code must be placed in a class module such as ThisOutlookSession
, and the DeleteMail()
procedure should be called before the event procedure can be called by Outlook.
Visual Basic for Applications |
---|
|
See Also