AbacusInfoTech
asked on
Get rid of "The DoMenuItem action was canceled"
Hello experts...
This one is a bit like:
https://www.experts-exchange.com/questions/21344953/Error-DoMenuItem-action-was-cancelled-when-save-record.html
and
https://www.experts-exchange.com/questions/21870778/Placing-of-code-to-supress-error-messages-DoCmd-SetWarnings.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.
This one is a bit like:
https://www.experts-exchange.com/questions/21344953/Error-DoMenuItem-action-was-cancelled-when-save-record.html
and
https://www.experts-exchange.com/questions/21870778/Placing-of-code-to-supress-error-messages-DoCmd-SetWarnings.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.
ASKER
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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).
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).
ASKER
Thanks harfanq, i'll look at this. My last post was in reponse to LPurvis...
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.
See Markus' (harfang) subsequent post for details.
Sorry for the snatch, Leigh; took me too long to write the two versions, and naturally I didn't refresh...
(^v^)
(^v^)
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.
:-)
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.
:-)
ASKER
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...!
I'm going to up the points a tiny bit and then split because you were of course both on the right track.
Thanks...!
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!
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!
ASKER
No worries rockiroads.. i'm sure there will be more q's to follow this week.
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
Its gonna be a great weekend, just hope the weather stays nice in Frankfurt
lol that's _some_ advance winding down you've got going on there ;-)
ASKER
:-)
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°)
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°)
ASKER
Yep, I spotted that. Ta.
Thanks for the weather forecast Leigh
Just "working???" the 4 days this week.
Everthing planned, just counting down the days
Just "working???" the 4 days this week.
Everthing planned, just counting down the days
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