Michael
Michael

Reputation: 3239

MS Access hitting cancel on query enter parameter box gives runtime error 2001

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?

Upvotes: 1

Views: 3350

Answers (1)

Andre
Andre

Reputation: 27644

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

Upvotes: 3

Related Questions