DoMenuItem action was canceled

J

Jim L.

Hey all...

I click on save record, my BeforeUpdate event fires, I
click cancel, then I get 'The DoMenuItem action was
canceled'. My Sub for BeforeUpdate doesn't have a
DoMenuItem, but the Save button has an Onclick event with
the DoMenuItem.

How do I get around this.


Thanking you in advance
 
K

Ken Snell [MVP]

In the code that runs in the BeforeUpdate event, set the Cancel variable to
True in the part of the code that runs when you click Cancel on the message
box.
 
J

Jim L.

Okay, I already have that, I think it's right....here is
the code;



Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Changes were made to one or more fields. OK
to save changes?", vbOKCancel) = vbCancel Then
Cancel = True
'Me.Undo
End If

End Sub


Thanks again.
 
K

Ken Snell [MVP]

The code you've posted appears correct, and should not show the message box
that you're seeing.

However, are you using the "Save Record" menu item to save the record? Or
are you using a Save Record command button created by the wizard?
 
J

Jim L.

I have an OnClick Event as follows,


Private Sub SaveRecord_Click()
On Error GoTo Err_SaveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70

Exit_SaveRecord_Click:
Exit Sub

Err_SaveRecord_Click:
MsgBox Err.Description
Resume Exit_SaveRecord_Click

End Sub


I used the wizard to build the 'Save Record' button on my
form.

Thanks.
 
K

Ken Snell [MVP]

This code is the source of your error message. Trap for it in the code:


Private Sub SaveRecord_Click()
On Error Resume Next

DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70

Select Case Err.Number
Case 0, 2001
Exit Sub
Case Else
MsgBox Err.Description
End Select

End Sub
 
J

Jim L.

Okay, so this is getting out of my league. I do not
understand the Select Case code you suggested, but I put
it in and still get the same error.

Sorry to be such a pain, but do you have any other ideas??

Thanks again.

-----Original Message-----
This code is the source of your error message. Trap for it in the code:


Private Sub SaveRecord_Click()
On Error Resume Next

DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70

Select Case Err.Number
Case 0, 2001
Exit Sub
Case Else
MsgBox Err.Description
End Select

End Sub
--

Ken Snell
<MS ACCESS MVP>

I have an OnClick Event as follows,


Private Sub SaveRecord_Click()
On Error GoTo Err_SaveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70

Exit_SaveRecord_Click:
Exit Sub

Err_SaveRecord_Click:
MsgBox Err.Description
Resume Exit_SaveRecord_Click

End Sub


I used the wizard to build the 'Save Record' button on my
form.

Thanks.
-----Original Message-----
The code you've posted appears correct, and should not show the message box
that you're seeing.

However, are you using the "Save Record" menu item to save the record? Or
are you using a Save Record command button created by
the
wizard?


.
 
K

Ken Snell [MVP]

Sorry - typo in my code:

Private Sub SaveRecord_Click()
On Error Resume Next

DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70

Select Case Err.Number
Case 0, 2501
Exit Sub
Case Else
MsgBox Err.Description
End Select

End Sub
 
K

Ken Snell [MVP]

If this isn't working yet for you, then read the actual error number that
you see on the error message box, and replace 2501 with that error number in
the code that I posted.

Select Case is a way in code to do things similarly to If...Then...Else
selections. It's easier to use for multiple possibilities.

--

Ken Snell
<MS ACCESS MVP>

Ken Snell said:
Sorry - typo in my code:

Private Sub SaveRecord_Click()
On Error Resume Next

DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70

Select Case Err.Number
Case 0, 2501
Exit Sub
Case Else
MsgBox Err.Description
End Select

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