Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 798
  • Last Modified:

Get rid of "The DoMenuItem action was canceled"

Hello experts...

This one is a bit like:
http://www.experts-exchange.com/Databases/MS_Access/Q_21344953.html
and
http://www.experts-exchange.com/Databases/MS_Access/Q_21870778.html (My own question!)

But I still can't figure it out.

I have this code in the beforeupdate property of my form:

If Nz(Me!title, "") = "" Then
    Beep
    MsgBox "Please enter a title for this Internal Consultant.", vbInformation, "Field Required"
    Cancel = True
    Me.title.SetFocus
    Exit Sub
End If
If Nz(Me!fullname, "") = "" Then
   Beep
   MsgBox "Please enter a name for this Internal Consultant.", vbInformation, "Field Required"
   Cancel = True
   Me.fullname.SetFocus
   Exit Sub
End If
    Me.btnClose.Enabled = True
    Me.BtnUndo.Enabled = False
    Me.btnSave.Enabled = False
    Me.btnClose.SetFocus

I just want to get rid of the "The DoMenuItem action was canceled" message that appears after I click OK on the MSgBox.

0
AbacusInfoTech
Asked:
AbacusInfoTech
  • 8
  • 4
  • 4
  • +1
2 Solutions
 
rockiroadsCommented:
why dont u put this lot

Me.btnClose.Enabled = True
    Me.BtnUndo.Enabled = False
    Me.btnSave.Enabled = False
    Me.btnClose.SetFocus


In the AfterUpdate property

If u dont set Cancel = True in BeforeUpdate, it will do the Update
setting buttons there should not really be in there, BeforeUpdate is used for validation purposes
0
 
AbacusInfoTechAuthor Commented:
I see your point about moving the 'button' code to AfterUpdate, I've done that without a problem.

I don't understand entirely what you are saying about cancel = True.

I don't want the record to save if it fails the validation.



0
 
Leigh PurvisDatabase DeveloperCommented:
You have a save button at all?
Something that attempts to save the form.

You'll need to error handle in there - for the cancellation of the Update.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
harfangCommented:
Hello AbacusInfoTech

Do you by any chance call this code from another sub? For example your Save button? In that case, you need to do check for the error number 2501, like this:


Private Sub cmdSave_Click()

On Error GoTo Error_Label

    DoCmd.RunCommand acCmdSaveRecord
   
Exit_Label:
    Exit Sub
   
Error_Label:
    If Err.Number = 2501 Then
        ' action was canceled
    Else
        MsgBox Err.Description, vbInformation
    End If
    Resume Exit_Label
   
End Sub


I would probably not code it in so many lines...


Private Sub cmdSave_Click()

On Error GoTo Error_Label

    DoCmd.RunCommand acCmdSaveRecord
    Exit Sub
   
Error_Label:
    If Err <> 2501 Then _
        MsgBox Err.Description, vbInformation
    Err.Clear
   
End Sub


Same idea, though. BTW, the DoMenuItem error code is the same (2501), but you should use RunCommand for readability and compatibility.

(°v°)
0
 
AbacusInfoTechAuthor Commented:
Yep, I have a plain old save button as follows:

Private Sub btnSave_Click()
On Error GoTo Err_btnSave_Click
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_btnSave_Click:
    Exit Sub
Err_btnSave_Click:
    MsgBox Err.description
    Resume Exit_btnSave_Click
End Sub

Please npte that because this is a multiple form, it is possible that a record could be saved without clicking on the save button. (e.g. by clicking into another existing record or tabbing to the next new record).
0
 
AbacusInfoTechAuthor Commented:
Thanks harfanq, i'll look at this. My last post was in reponse to LPurvis...
0
 
Leigh PurvisDatabase DeveloperCommented:
Yeah - but it's only when executed through code that you'll get the error (as technically the Save has failed by being cancelled).

See Markus' (harfang) subsequent post for details.
0
 
harfangCommented:
Sorry for the snatch, Leigh; took me too long to write the two versions, and naturally I didn't refresh...
(^v^)
0
 
Leigh PurvisDatabase DeveloperCommented:
Naturally - which of us does? lol

No probs at all - in fact AbacusInfoTech is probably as well off to ignore my posts - as they've passed and crossed over and such and it might be clearer to just see the one thread.
:-)
0
 
AbacusInfoTechAuthor Commented:
Clever geezers aren't you?

I'm going to up the points a tiny bit and then split because you were of course both on the right track.

Thanks...!



0
 
rockiroadsCommented:
AbacusInfoTech

Your code was on the right track when it comes to uses cancel = true on form_beforeupdate (assuming this is a bounded form)
cancel = true forces it so no data is updated, record is left in the state just before an update is to occur.

I was away which is why I didnt respond earlier, but I see this thread has been busy!


0
 
AbacusInfoTechAuthor Commented:
No worries rockiroads.. i'm sure there will be more q's to follow this week.
0
 
rockiroadsCommented:
Ive already started to wind down in preparation for this weekend!!!
Its gonna be a great weekend, just hope the weather stays nice in Frankfurt
0
 
Leigh PurvisDatabase DeveloperCommented:
lol that's _some_ advance winding down you've got going on there ;-)
0
 
AbacusInfoTechAuthor Commented:
0
 
AbacusInfoTechAuthor Commented:
:-)
0
 
harfangCommented:
Well, that was fun!

One last thing: put the line with btnClose.Setfocus higher up, or your next bug will be "you can't disable a control while it has the focus"...

    Me.btnClose.Enabled = True
    Me.btnClose.SetFocus
    Me.BtnUndo.Enabled = False
    Me.btnSave.Enabled = False

Cheers all!
(°v°)
0
 
AbacusInfoTechAuthor Commented:
Yep, I spotted that. Ta.
0
 
rockiroadsCommented:
Thanks for the weather forecast Leigh

Just "working???" the 4 days this week.

Everthing planned, just counting down the days
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now