RunCommand action was canceled

  • Thread starter scottyb121 via AccessMonster.com
  • Start date
S

scottyb121 via AccessMonster.com

I am trying to delete a record using a command button on the onclick event
procedure in my patient form. When I click yes on the MsgBox I get a
RunCommand action was canceled error and the record is not deleted. I have
the EXACT same code for a schedule record on a schedule form and it works
just fine. I have the allow deletions property to yes on the form so that
isn't it. I am completely stumped. Here is my code for deleting a record in
the patient form.

response = MsgBox("You are about to delete this Patient record. " & _
vbCrLf & vbCrLf & _
"Are you sure you want to do this?" & vbCrLf & vbCrLf &
_
" YES - Delete this Patient record" & vbCrLf & _
" NO - Do NOT delete this Patient record" & vbCrLf, _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"Confirm Patient Record Deletion")

If response = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
DoCmd.Close
End If
 
A

Allen Browne

Just these 2 lines should do it:
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

Access will ask for confirmation, or you can craft your own.
 
S

scottyb121 via AccessMonster.com

I put in those two lines and I still get the "RunCommand action was canceled"
error. I also don't understand why the same code works in two other forms
but won't work in this one. I am basically doing the same thing in all the
forms.

Allen said:
Just these 2 lines should do it:
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

Access will ask for confirmation, or you can craft your own.
I am trying to delete a record using a command button on the onclick event
procedure in my patient form. When I click yes on the MsgBox I get a
[quoted text clipped - 24 lines]
DoCmd.Close
End If
 
A

Allen Browne

Okay, so the problem is to identify what is cancelling the deletion.

If the record is being edited, it has to be saved before it can be deleted.
We addressed that situation by undoing it.

The next possibility is that it is at a new record (where entry of a new
record may have begun.) We addressed that situation by testing for
NewRecord.

If it's neither of those, you are looking for other possibilities such as:
- The form's RecordSource is a query that you can't delete from.

- Something is cancelling the form's Delete or BeforeDelConfirm event.

- The code is in the wrong event, where something else has to happen before
the deletion can proceed.

- You don't have permission to delete (Access security, Windows/network
permissions, data is on a CD, etc)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

scottyb121 via AccessMonster.com said:
I put in those two lines and I still get the "RunCommand action was
canceled"
error. I also don't understand why the same code works in two other forms
but won't work in this one. I am basically doing the same thing in all the
forms.

Allen said:
Just these 2 lines should do it:
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

Access will ask for confirmation, or you can craft your own.
I am trying to delete a record using a command button on the onclick
event
procedure in my patient form. When I click yes on the MsgBox I get a
[quoted text clipped - 24 lines]
DoCmd.Close
End If
 

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