Code to cancel a record deletion

S

Seth Schwarm

Access XP

Access 2000 format

What code do I need to write on a Before Del Confirm
event to cancel a record deletion?

This is how I want it to work. User clicks the delete
button on the standard Access toolbar. If records in
joined table exist I want to cancel the deletion using a
message box on the Before Del Confirm event. This way I
can communicate with the user and tell them why the
record will not be deleted.

The part I don't know how to write is how to cancel a
delete action already put into play by clicking the
delete button the the standard toolbar.

Thanks,

Seth
 
B

Bruce M. Thompson

What code do I need to write on a Before Del Confirm
event to cancel a record deletion?

This is how I want it to work. User clicks the delete
button on the standard Access toolbar. If records in
joined table exist I want to cancel the deletion using a
message box on the Before Del Confirm event. This way I
can communicate with the user and tell them why the
record will not be deleted.

The part I don't know how to write is how to cancel a
delete action already put into play by clicking the
delete button the the standard toolbar.

Try using the "On Delete" event procedure for this:

'***EXAMPLE START
Private Sub Form_Delete(Cancel As Integer)

If [the condition is met] Then
Cancel = True
MsgBox "You cannot delete this record."
End If

End Sub
'***EXAMPLE

In any case, you can prevent the deletion of records on the "One" side when
records exist on the "Many" side of a relation by setting, in the "Edit
Relationships" dialog, the "Enforce Referential Integrity" check box to True and
leaving "Cascade Delete Related Records" set to False.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top