Delete, BeforeDelConfirm, AfterDelConfirm Events - Event Procedures

Delete, BeforeDelConfirm, AfterDelConfirm Events — Event Procedures

See Also         Example

To create an event procedure that runs when a Delete, BeforeDelConfirm, or AfterDelConfirm event occurs, set the OnDelete, BeforeDelConfirm, or AfterDelConfirm property to [Event Procedure], and click the Build button .

Syntax

Private Sub Form_Delete(Cancel As Integer)

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)

Private Sub Form_AfterDelConfirm(Status As Integer)

The Delete event procedure has the following argument.

Argument Description
Cancel The setting determines if the Delete event occurs. Setting the Cancel argument to True (–1) cancels the Delete event.

The BeforeDelConfirm event procedure has the following arguments.

Argument Description
Cancel The setting determines if the BeforeDelConfirm event occurs. Setting the Cancel argument to True cancels the BeforeDelConfirm event and prevents the Delete Confirm dialog box from being displayed. If the event is canceled, the original records are restored, but the AfterDelConfirm event still occurs. If Cancel is set to True, the Response argument is ignored.
  If Cancel is set to False (0), which it is by default, the value in the Response argument is used by Microsoft Access to determine the type of response to the delete event.
Response The setting determines whether Microsoft Access displays the Delete Confirm dialog box asking if the record should be deleted. The Response argument can be set to one of the following intrinsic constants:
  Constant Description
  acDataErrContinue Continues without displaying the Delete Confirm dialog box. Setting the Cancel argument to False and the Response argument to acDataErrContinue enables Microsoft Access to delete records without prompting the user.
  acDataErrDisplay (Default) Displays the Delete Confirm dialog box.

The AfterDelConfirm event procedure has the following argument.

Argument Description
Status The setting indicates whether a record has been deleted. The Status argument can be any of the following intrinsic constants:
  Constant Description
  acDeleteOK Indicates the deletion was successful.
  acDeleteCancel Indicates the deletion was canceled in Visual Basic.
  acDeleteUserCancel Indicates the deletion was canceled by the user.

Remarks

The AfterDelConfirm event can't be canceled.

You can use these events to customize how records are deleted. For example, when a user deletes a record, such as an employee record, the Delete event occurs. You can place code in the Delete event procedure to save the data from the Employee ID and Name fields in a set of temporary variables. When the BeforeDelConfirm event occurs, you can prevent the Delete Confirm dialog box from being displayed by setting the Response argument to acDataErrContinue. This enables you to display a custom dialog box. When the AfterDelConfirm event occurs and the Status argument is set to acDeleteOK, you can clear the temporary variables, or save the employee information in another table.