Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2003
    Posts
    34

    Unanswered: DoMenuItem action was canceled

    I have a button on my form that pops up a yesnocancel message box.

    Here is the code on the form:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim iAns As Integer
    If Me.Dirty Then
    strMsg = "Are you sure you want to save this record?" & vbCrLf
    strMsg = strMsg & "Click Yes to Save the Record, No to Delete the Record, or Cancel to Return to the Record."
    iAns = MsgBox(strMsg, vbQuestion + vbYesNoCancel)
    If iAns = vbNo Then
    Me.Undo
    ElseIf iAns = vbCancel Then
    Cancel = True
    Else
    End If
    End If
    End Sub

    (Don't hurt me, I copied that code from somewhere else and then just modified it for my uses.

    Yes and No work fine, but of course, when I hit Cancel, I get "The DoMenuItem action was canceled."

    I say of course because I gather that other people have also had this problem. After some Googling, I tried the setwarnings command (although the Access helpfile says that command doesn't prevent messages from popping up, only from interrupting macros - ?). I'm also not sure exactly where to place that command line, anyway.

    I only get this error when I try to return to a record without saving or deleting it. I'm reiterating that, just because I saw a solution for this sort of problem that involved a BeforeDelConfirm event on the main form, and that did not work either... possibly because I'm not actually deleting anything?

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    You could try docmd.cancelevent rather than cancel = -1, but if Form_BeforeUpdate is running, then clicking that button is either running it explicitly or you have left the form or subform which is triggering Access to save the record. Is there any going back at this point? Is cancel event a possibility at this point?

  3. #3
    Join Date
    Oct 2003
    Posts
    34
    Doing that does indeed get rid of the DoMenuItem warning, but then I this message box pops up:

    "You canceled the previous operation." [OK]

    Well, yes. Yes, I did.

  4. #4
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    Now will a setwarnings = 0 get rid of that message?

  5. #5
    Join Date
    Oct 2003
    Posts
    34
    Where should I put that?

    Within Private Sub Form_BeforeUpdate, it causes the button click to go straight to a compile error: "Argument not optional".

  6. #6
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    You mentioned that you had tried the set warning command earlier, so I did not supply the full syntax:

    docmd.setwarnings = 0

    This may get rid of the argument not optional error

    I must ask again, why are you trying to cancel an event where access requires a full save or a rollback?

  7. #7
    Join Date
    Oct 2003
    Posts
    34
    Yes, I used the full syntax for setwarnings, and that gave me the compile error. I tried it both inside and outside of the If.

    I'm sorry, I didn't understand at first about the cancel question... I may be doing something very strange, then. I was simply trying to give a labelled escape to the user; if they hit Yes, their data is saved and disappears. If they hit No, their data is not saved... and still disappears. I wanted them to have an option just in case they hit the button accidentally and didn't want to have to retype in a bunch of entries... the form is rather large. The users are most likely at a low level of computer experience (even lower than me! ) so I'm not expecting them to know for sure that the close button will cancel just as effectively.

    Under the circumstances, if it's not possible to do anything else, I'm satisfied with the "You canceled the previous operation" msg. It's fairly simple and friendly, and most likely the users will not need the Cancel button anyway.

    (In which case, why am I so worried about all of this? *sigh* Perfectionism...)

  8. #8
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    When I want more control, I will create the form based on temporary tables then insert into the main database only when the user hits save or accept. This works well in a multi user environment when issuing a key is only done when the form is saved, like an order form, journal entry batch, or invoice. In this manner, cancel does have significance.

  9. #9
    Join Date
    Nov 2009
    Posts
    223
    I have just put a wizard-created button on one of my Forms and get the same message.

    I do not know VBA or SQL. is there somewhere in the Properties field of the button where I can turn off this message?

    Thanks in advance.

    Red Devil

  10. #10
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    I rarely use wizard created buttons as they too often produce effects that I can program around. Your message is one good example. Can you please post the vb code that gets run by the button the wizard created? -- John M Reynolds
    John M Reynolds

  11. #11
    Join Date
    Nov 2009
    Posts
    223
    hi jmrSudbury,

    Thanks for your reply.

    I have just re-checked all my Delete buttons and they all seem to work correctly?? no sure why the error came originally.

    Thanks for the offer of help, but it all looks OK now.

    Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •