The DoMenuItem action was canceled.

S

Steve B

Afternoon,

With previous help from this group, I now understand basic form validation.

I have two Combo boxes, I have set up validation so that if one particular
option is selected from the 1st combo, the user must select an option from
the second box. If they don't and press the save button the validation pops
up, however when they press no, a second box appears stating "The DoMenuItem
action was canceled."

I have searched around and suggestion such as add "DoCmd.SetWarnings false"
in the Save button function, but it still gives me the second error.

The form has a beforeupdate validation event as this
----------------------------------------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me!cbQueryType = "Poor Build Quality" Then
If IsNull(Me!cbPoorBuild) Then
MsgBox "Poor Build! Please enter Poor Build Reason!", vbOKOnly
Cancel = True

Me!cbPoorBuild.SetFocus
End If
End If
----------------------------------------------------------------
And the save button event is
----------------------------------------------------------------
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_cmdSaveRecord_Click:
Exit Sub

Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click

End Sub

----------------------------------------------------------------

I've tried putting the "DoCmd.SetWarnings false" in various places and it
always fails.

Any suggestions?

Thanks

Steve
 
K

Ken Snell \(MVP\)

What's likely happening is that the BeforeUpdate's validation is failing for
the record that you're trying to save when you click the button. When the
BeforeUpdate event procedure's code cancels the BeforeUpdate event, then the
DoCmd.MenuItem step will fail, causing the error message that you're seeing.

What I suggest is that you also put the BeforeUpdate's validation in the
Click event, so that you can avoid this problem (it's easier to do this than
it is to try to trap the error that will result from the BeforeUpdate
cancellation):

Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click

If Me!cbQueryType = "Poor Build Quality" Then
If IsNull(Me!cbPoorBuild) Then
MsgBox "Poor Build! Please enter Poor Build Reason!", vbOKOnly
Cancel = True

Me!cbPoorBuild.SetFocus

Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

End If

Exit_cmdSaveRecord_Click:
Exit Sub

Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click

End Sub
 
S

Steve B

Thanks Ken - It makes sense now from you explanation.

Thank you for you assistance, another piece of Access magic explained.

Steve
 

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