Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following example illustrates how to use a form's Delete event to prevent the deletion of a record based on custom criteria. In this example, the Delete event is canceled if the value of the DataRequired field is Yes.
Private Sub Form_Delete(Cancel As Integer)
' Check the value of the DataRequired field.
If Me.DataRequired = "Yes" Then
' Cancel the record deletion.
Cancel = True
' Notify the user.
MsgBox "Cannot Delete the Record."
End If
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.