Disabling "The DoMenuItem action was canceled."

G

Guest

Hello.
I have a button in a menu which is meant to delete record currently
displayed in a form. When I click it, it shows a message window asking user
weather he wants to delete a record. If the user clicks "No", this message is
shown.
I've already found the answer to this question, but it seems that it works
only for buttons that are on the form itself, not in case button is in a menu.
The function which that button is linked to is as follows:

Function menu_delete()
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Function

DoCmd.SetWarnings commands does not solve this problem.

Can anybody help?
 
A

Albert D. Kallal

In most cases, my custom menu buttons call code in the form anyway.....

So, any particular reason why you don't have the button call your code in
the form???


Just make sure your function in the form is public

eg:

Public Function MyDelete

DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

End Function


Now, for your custom menu button, simply place the name of the function in
the "on action" setting

eg:

=MyDelete()

the button will now run your code in the form.

As I mentioned, about 99% of the time, custom menu buttons do run code in
the form, just like having a button on the form.
 
G

Guest

Making the function public did not solve the problem. I know that it runs a
code in a form, that's where the function is, but still it does not work
me... Any other solutions to this problem?
 
A

Albert D. Kallal

Ah, ok..I did not read you question too close...


The problem is when you say "no"....

You have to error trap, just use:


Public Function MyDelete()

On Error GoTo exit1:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
exit1:

End Function
 

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