Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

suppress "the domenuitem action was cancelled" error 1

Status
Not open for further replies.

fredk

Technical User
Jul 26, 2001
708
US
I have a form where I add data - I set an if statement in the before update event that checks to see:

"if a bonus checkbox and any of the error checkboxes are selected"

If so, there is a message box that tells the user that they cannot check the bonus checkbox if there are errors.

It works, however, I get the domenuitem was cancelled error - Was looking for direction in how to suppress it - I am guessing I need to add an if statement to the error portion?

Thanks!!!

Fred
 
Is it the 2501?

[tt]if err.number<>2501 then
msgbox err.description
end if
resume myexit[/tt]

if it isn't 2501, do a msgbox err.number to find the correct number...

Roy-Vidar
 
Roy - as always, you are the man.

I am not sure what the number is (it does not give it to me)

I will give it a whirl tomorrow when I am back in work

Thanks again!!!

Fred
 
Hi Roy - I am not sure where to put the error information - I added it to my code (which is in the beforeupdate event) but it is not triggering - perhaps if I post all the code - Please be kind, I am still learnin

Private Sub Form_BeforeUpdate(cancel As Integer)
Dim ctl, CtlA As Control, Ct As Integer, MyStr As Variant
Dim bonuserror As String
On Error GoTo Err_form_beforeupdate

Ct = 0
If Me.Check22 = True Then
'enumerate controls collection

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Ct = Ct + 1
MyStr = "text" & CStr(Ct)
For Each CtlA In Me.Controls
If CtlA.Name = MyStr Then
If CtlA.Value > 0 Then
bonuserror = "yes"
End If
End If
Next CtlA
End If
Next ctl
End If
If bonuserror = "yes" Then
MsgBox "You cannot have the bonus checked if there are errors"
'cancel = True
End If

Exit_form_beforeupdate:
Exit Sub


Err_form_beforeupdate:
MsgBox Err.Number
Resume Exit_form_beforeupdate

Thanks!!!

Fred
 
Ignore the comments tick mark before the cancel=true - is there another way to undo the record?

Thanks!!!

Fred
 
I just thought of something - If I move my code from the beforeupdate event to the save button. Dup!

Now it seems to work - Any feedback on improvment would be appreciated!!

Thanks!!!

Fred
 
What isn't triggering? The before update (should trigger on any attempt to save)?

I fail to see where you've put my sample, it should be in the error handling, just testing wich error, and only display a message for other errors than 2501. But where is the menuitem stuff?

As you've built your errorhandler, it should display the error number for any error occuring within the before update.

I'm guessing you have some other routine doing some menuitem stuff, save, refresh... (without errorhandling), that invokes the before update (if it is the before update providing the error?)

Cancel = true in the before update doesn't undo anything, just throw you back to the record to make it possible to amend the record, to undo, use [tt]me.undo[/tt].

Using the before update means the validation occurs on any attempt to save. Putting it behind a button invokes it only when the button is clicked, not when the user hits SHIFT+Enter, moves between records, hits some menu thingies doing a refresh/save/requery... (which would all save the record)

Roy-Vidar
 
Thanks for responding - I thought by adding the

"MsgBox Err.Number"

that I would get the error number when I saved the record - I just got the actual message "the domenuitemaction was cancelled"

when I had cancel=true it did not save the record - just gave me the domenuitemacion was cancelled message

thanks for pointing out the limits of adding my code to the button - did not think of that.

When I added me.undo it resumed and saved the record

When the form is first launched, the on load event is coded to take data from the main form and populate some fields - you are right that I do not have error handling in that procedure.

????


Thanks for all of your help!!!!

Fred

 
Then the error occurs somewhere else - as I said, somewhere where you're doing some menuitem thingies (which might or might not invoke the before update, probably the first). But since the before update was cancelled (without any error), that menuitem tingie wasn't exececuted - providing the "cancel" message. If you got a message box stating that message, without any debug button, this is probably in a routine where you have msgbox err.description in your errorhandler - that's where you should trap for it (I sometimes find it usefull for trapping such, to comment all lines starting with On Error Goto - which will give the awful Debug thingie providing the offending line...). This is among the "fun stuff" of forms programming - having events calling events calling events, and you loose control of what's actually happening... try adding a breakpoint on the first executable line of every event procedure of the form, and perform what you do to trigger this event/errormessage...

Roy-Vidar
 
Got it Roy - I will try that now -

Thanks for all of your help!!!!!!


Fred
 
I was selecting the "save" button - that is what the domenuitem was -

If I go to the next record or use the shift enter I get the expected results - It is because I am selecting the save record button which has DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70 -

Now I just need to fix that and I will be set


Thanks again!!!

Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top