MS Access击中查询输入参数框取消给出运行时错误2001 [英] MS Access hitting cancel on query enter parameter box gives runtime error 2001

查看:269
本文介绍了MS Access击中查询输入参数框取消给出运行时错误2001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的MS Access表单,当单击这些按钮时,将打开一个表并通过单击事件->打开表单命令进行查询.将打开参数框,但是当我按取消"时,会出现一个标题为"Macro Single Step"的窗口,提示错误号: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.

如何在不出现错误的情况下按取消"?按下按钮时我根本不使用VBA,那么如何捕获此错误而不显示该错误?

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?

更新:我发现,在设计视图中,如果我在按钮的on click事件中单击嵌入式宏,则存在"On Error"选项.填写两部分:转到"和宏名称".进入以下选项:下一步,宏,失败.如何指定不执行任何操作"类型的操作?

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?

推荐答案

如注释中所述,使用VBA更加容易和干净,因为可以忽略错误(通过按取消").

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

这篇关于MS Access击中查询输入参数框取消给出运行时错误2001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆