1
votes

I have an MS Access form with buttons that when clicked, open up tables and queries through an on-click event --> open form command. The parameter box opens, but when I press cancel a window titled "Macro Single Step" appears saying Error Number: 2001. There's a button called Stop All Macros here.

How can I press cancel without getting an error? I don't use VBA at all when the button is pressed so how can I catch this error and not display it?

Update: I found out that in design view if I click on my embedded macro in the on click event of the button, there's an option for "On Error". There are two parts to fill out: "Go to" and "Macro Name". Go to has the options: Next, Macro, fail. How can I specify a "do nothing" kind of action?

1
It would be really easier to use VBA, where you can do On Error Resume Next if you want to ignore canceling.Andre
You're right it would be much easier, I had to do that with some other buttons and made error handling very convenient. The only problem here is that I would then have to open the query up through VBA code which is what I wanted to avoid for simplicityMichael
DoCmd.OpenQuery "myQuery" - a macro can't really be simpler. :)Andre
I just found that one too, you're right very easy :)Michael

1 Answers

3
votes

As discussed in the comments, it is easier and cleaner to use VBA, where the error (by pressing Cancel) can simply be ignored.

Private Sub cmdOpenMyQuery_Click()

    ' If the query contains parameters, and the user may cancel opening it: ignore that error
    On Error Resume Next
    DoCmd.OpenQuery "myQuery"

End Sub