Displaying Custom Dialog Boxes for Custom Delete Actions in Access 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.
Applies to: 2007 Microsoft Office system, Microsoft Office Access 2007
Joel Krist, Akona Systems
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:
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.
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
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
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
Video Length: 00:04:30
File Size: 3.05 MB WMV