Cancel Record code is not working

J

Jan Il

Hi all - Access 2002 XP, W2K

I have a entry form on which I have a command button with the code below
that cancels the current entry if desired. When I cancel the entry, I get a
debugger error message that says:

Runtime error: 2046
The command or action 'Undo' is not available now.

It appears to balk at this part of the code which is highlighted in yellow:

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub cmdCancelRec_Click()
Dim Response As Variant

Response = MsgBox("Are your sure you want to cancel?", vbYesNo,
"Confirmmation Required!")
If Response = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.GoToRecord , , acNewRec
Exit Sub
End If

Exit_cmdCancelRec_Click:
Exit Sub

Err_cmdCancelRec_Click:
MsgBox Err.Description
Resume Exit_cmdCancelRec_Click

End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have this code in another form and there are no errors at all, it works
just fine. So, I'm not sure what I have done incorrectly that is causing
this error in this form, as it does cancel the entry. I'd truly appreciate
it if someone would let me know where the mis-step is in this code. I am
obviously just not seeing it.

Jan :)
 
M

MacDermott

Hi, Jan!

See you've found yourself another dragon.
DoMenuItem can be a real bear (or should I say dragon?) to debug, because it
refers to the order of items on the menus on version 7 of Access.
(Apparently MS put a lot of work into developing the wizards which write
that code, and decided it was safer to bring the antiquated code forward
than to redevelop it using the more modern syntax. Or so I've heard.)

To "undo" an entire record, try using
Me.Undo
(you can also undo a single control using MyControl.Undo.)

HTH
- Turtle
 
J

Jan Il

Hey Turtle! How are you? :)
Hi, Jan!

See you've found yourself another dragon.
DoMenuItem can be a real bear (or should I say dragon?) to debug, because it
refers to the order of items on the menus on version 7 of Access.
(Apparently MS put a lot of work into developing the wizards which write
that code, and decided it was safer to bring the antiquated code forward
than to redevelop it using the more modern syntax. Or so I've heard.)

Yeppers, you know me.......always have a Dragon smoldering in the wings.
;o))

Funny thing is, this same form has worked just fine for some time with this
code in place, and just now started to throw this error at me. I did just
do some additional modification for entering data the last day or so, some
code Dirk was working on with me down stream a bit, around the 4th, Debit
Card Purchase recording, so maybe that stirred it up. I use this same code
in Cancel buttons on several other data entry forms, and they all work ok.
The Save button code on this form still works fine. Don't know why this code
decided to pitch a hissy fit.
To "undo" an entire record, try using
Me.Undo
(you can also undo a single control using MyControl.Undo.)

On this, do you mean to replace the line DoCmd.DoMenuItem acFormBar,
acEditMenu, acUndo, , acMenuVer70 ....with the Me.Undo alone? Not sure on
that. I'm gonna keep the info on the single Control cancel code
too.......in case I need it for another Dragon. <G>

Thank you for you help, Turtle,I really appreciate it! :)

Jan :)
 

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