BeforeItemCopy Event

Microsoft Outlook Visual Basic

BeforeItemCopy Event

       

Occurs when an item is copied. This event can be cancelled after it has started.

Private Sub expression_BeforeItemCopy(Cancel As Boolean)

expression   An expression that returns an Explorer object declared with events in a class module.

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 copied.

Example

The following example prompts the user before an item is copied. A message is displayed to the user verifying that the item should be copied. If the user clicks Yes, the item is copied.

Private Sub objExplorer_BeforeItemCopy(Cancel As Boolean)
'Prompts the user before copying an item

   Dim lngAns As Long 'user answer
   'Display question to user
   lngAns = MsgBox("Are you sure you want to copy the item?", vbYesNo)
   If lngAns = vbYes Then
       Cancel = False
   Else
       'Set Cancel argument based on answer
       Cancel = True
   End If

End Sub