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

别等时光非礼了梦想. 提交于 2019-12-24 18:10:58

问题


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:


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


来源:https://stackoverflow.com/questions/37863630/ms-access-hitting-cancel-on-query-enter-parameter-box-gives-runtime-error-2001

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!