HandsOn Writing the Form BeforeDel Confirm Event Procedure

This hands-on uses the Product Categories form created in Hands-On 24-6.

1. In the Visual Basic Editor window, double-click Form_Product Categories, which was created in Hands-On 24-6 and modified in Hands-On 24-7.

2. In the Code window, two event procedures are shown that were prepared in Hands-On 24-6 and 24-7. Enter the following Form_BeforeDelConfirm event procedure below the last procedure code.

Private Sub Form_BeforeDelConfirm(Cancel _

As Integer, Response As Integer) Response = acDataErrContinue End Sub

In the procedure code above, this statement

Response = acDataErrContinue will suppress the default dialog box that Microsoft Access normally displays when you attempt to delete a record.

Part IV

3. To test the above event procedure, activate the Product Categories form and open it in Form view.

4. Add a new record, save it, and then delete it. The Form_Delete event procedure prepared in Hands-On 24-7 will be executed at this point, and you will see a dialog with your custom prompt to confirm the deletion. Click Yes. Notice that Access does not display its default message asking you to confirm the deletion of the specified number of records.

^^ Note: Instead of writing your custom confirmation message in the

Form_Delete event procedure, you can place it in the Form_BeforeDelConfirm event procedure as shown below:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, _

Response As Integer) ' remove the default Access dialog box that prompts to confirm deletion Response = acDataErrContinue

If MsgBox("Do you really want to delete this record?", _ vbOKCancel) = vbCancel Then Cancel = True End If End Sub

0 0

Post a comment