Cancel Delete Event Not Canceling

A

Andy

Hi;

Code is suppose to Cancel the Delete. It doesn't.

The first half does stop the Record from being deleted,
The second half, after ELSE, brings up the standard warning box informing:
"Relationships that specify cascading deletes are about to cause 1 record(s)
in this table and in related tables to be deleted.
Are you sure you want to delete these records."

Juse want the delete event to cancel.

Would someone be so kind and tell me what is missing?

Thank You.
Andy

Private Sub Form_Delete(Cancel As Integer)
If Me![chkbxDeleteBlockedYN] = True Then
Cancel = True
MSGBOX "This Record is Protected and can't be deleted."
Else
MSGBOX "Do You really want to delete this Record from the Database?",
vbOKCancel
Select Case Msg
Case vbYes
Cancel = False
Case vbCancel
Cancel = True
End Select

End If

End Sub
 
K

Ken Snell [MVP]

The form's BeforeDelConfirm event is creating the popup message box. Add
code to that event procedure:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Response = acDataErrContinue
End Sub
 
A

Amy Blankenship

In addition, you also need to set msg = MsgBox(...), because right now Case
msg will always be null. Also, you should probably get in the case of
declaring your variables, so start out the Form_BeforeDelConfirm with

dim msg as Integer

HTH;

Amy

Ken Snell said:
The form's BeforeDelConfirm event is creating the popup message box. Add
code to that event procedure:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Response = acDataErrContinue
End Sub

--

Ken Snell
<MS ACCESS MVP>

Andy said:
Hi;

Code is suppose to Cancel the Delete. It doesn't.

The first half does stop the Record from being deleted,
The second half, after ELSE, brings up the standard warning box
informing:
"Relationships that specify cascading deletes are about to cause 1
record(s)
in this table and in related tables to be deleted.
Are you sure you want to delete these records."

Juse want the delete event to cancel.

Would someone be so kind and tell me what is missing?

Thank You.
Andy

Private Sub Form_Delete(Cancel As Integer)
If Me![chkbxDeleteBlockedYN] = True Then
Cancel = True
MSGBOX "This Record is Protected and can't be deleted."
Else
MSGBOX "Do You really want to delete this Record from the Database?",
vbOKCancel
Select Case Msg
Case vbYes
Cancel = False
Case vbCancel
Cancel = True
End Select

End If

End Sub
 
K

Ken Snell [MVP]

Amy Blankenship said:
In addition, you also need to set msg = MsgBox(...), because right now
Case msg will always be null. Also, you should probably get in the case
of declaring your variables, so start out the Form_BeforeDelConfirm with

dim msg as Integer

HTH;

Amy


good catch.
 
A

Andy

Ken and Amy;

It works!!!

Thank You!!!

Andy

Ken Snell said:
see reply in other newsgroup where you posted this same question...

--

Ken Snell
<MS ACCESS MVP>

Andy said:
Hi;

Code is suppose to Cancel the Delete. It doesn't.

The first half does stop the Record from being deleted,
The second half, after ELSE, brings up the standard warning box informing:
"Relationships that specify cascading deletes are about to cause 1
record(s)
in this table and in related tables to be deleted.
Are you sure you want to delete these records."

Juse want the delete event to cancel.

Would someone be so kind and tell me what is missing?

Thank You.
Andy

Private Sub Form_Delete(Cancel As Integer)
If Me![chkbxDeleteBlockedYN] = True Then
Cancel = True
MSGBOX "This Record is Protected and can't be deleted."
Else
MSGBOX "Do You really want to delete this Record from the Database?",
vbOKCancel
Select Case Msg
Case vbYes
Cancel = False
Case vbCancel
Cancel = True
End Select

End If

End Sub
 

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