Export (0) Print
Expand All
6 out of 9 rated this helpful - Rate this topic

Displaying Custom Dialog Boxes for Custom Delete Actions in Access 2007

Office 2007

Summary: Learn how to display a custom dialog box in Microsoft Office Access 2007 that asks users to confirm that they want to delete a record.

Office Visual How To

Applies to: 2007 Microsoft Office system, Microsoft Office Access 2007

Joel Krist, Akona Systems

April 2007

Overview

In Microsoft Office Access 2007, when the user selects and deletes a record on a form, Access displays a dialog box that asks the user to confirm the deletion. There are two ways to suppress the dialog box so that it does not appear:

  • Cancel the BeforeDelConfirm event. This cancels the deletion. For more information about the BeforeDelConfirm event, see BeforeDelConfirm Event.

  • Set the Response argument of the BeforeDelConfirm event procedure to acDataErrContinue. This confirms the deletion.

You can also use the BeforeDelConfirm event procedure to display a custom dialog box to handle responses from users. This article describes how to use a custom dialog box to ask users whether they want to cancel or continue with the record deletion.

Code It

This section demonstrates how to display a custom dialog box in response to a record deletion. The procedure has two steps.

To display a custom dialog box in response to a record deletion

  1. Add a BeforeDelConfirm form event procedure to a form.

  2. Add the record deletion confirmation code to the event procedure.

1. Add a BeforeDelConfirm Form Event Procedure

First, load the form and display it in Design View. To do this, right-click the form name in the Navigation Pane and select the Design View menu item from the context menu. After the form is displayed in Design View, select the Design tab on the Office Fluent Ribbon and in the Tools group select the Property Sheet button. The form's property sheet appears.

Next, on the form's property sheet, select Form in the Selection type drop-down list, and then select the Event tab to display the form's events. Click the BeforeDelConfirm event and select the small down arrow that is displayed. Click the [Event Procedure] item and then click the ellipsis next to the small down arrow. will load and display the body for the Form_BeforeDelConfirm subroutine.

2. Add Code to the BeforeDelConfirm Event Procedure

Next, modify the Form_BeforeDelConfirm event procedure created earlier in this article so that it uses the MsgBox function to prompt the user for confirmation of the record deletion. The following code checks the return value from the MsgBox call, and if the user selects Yes, the code tells Access to continue with the deletion by setting the Response argument passed to the event procedure equal to acDataErrContinue. If the user selects No, the code cancels the record deletion by setting the Cancel argument passed to the event procedure equal to True.

Private Sub Form_BeforeDelConfirm(Cancel As Integer, _
    Response As Integer)
    Dim strMessage As String
    Dim intResponse As Integer
    
    On Error GoTo ErrorHandler
    
    ' Display the custom dialog box.
    strMessage = "Would you like to delete the _
        current record?"
    intResponse = MsgBox(strMessage, vbYesNo + _
        vbQuestion, _
        "Continue delete?")
    
    ' Check the response.
    If intResponse = vbYes Then
        Response = acDataErrContinue
    Else
        Cancel = True
    End If
    
    Exit Sub
    
ErrorHandler:
    MsgBox "Error #: " & Err.Number & vbCrLf & _
        vbCrLf & Err.Description
End Sub
Read It

In many cases, you might want to display a custom dialog box when Access prompts to confirm a record deletion, instead of the usual Yes/No dialog box. You can use the BeforeDelConfirm event procedure to create a custom dialog box to handle responses from users. This article describes how to use a custom dialog box to ask users whether they want to cancel or continue with the record deletion.

This article explores how to display a custom dialog box in response to a record deletion on an Access 2007 form.

To display a custom dialog box in response to a record deletion on an Access 2007 form

  1. Add a BeforeDelConfirm form event procedure to a form. In this step you add the BeforeDelConfirm event and build the body for the Form_BeforeDelConfirm subroutine.

  2. Add the record deletion confirmation code to the event procedure. As part of this final step, you add code to the custom MsgBox form to capture a custom response. The user's selection determines whether the record is deleted or if the deletion is canceled.

See It

Screenshot of Custom Delete Actions video

Watch the Video

Video Length: 00:04:30

File Size: 3.05 MB WMV

Explore It
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.