DoCmd.SetWarnings 和 CurrentDB.Execute 有什么区别 [英] What's the difference between DoCmd.SetWarnings and CurrentDB.Execute

查看:31
本文介绍了DoCmd.SetWarnings 和 CurrentDB.Execute 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在关于这个答案的评论中,Remou写道

In the comments on this answer, Remou writes that

CurrentDB.Execute "insert sql here"

DoCmd.SetWarnings = 0
DoCmd.RunSQL在此处插入sql"

由于 Access 产生的内置警告.我正在努力了解其中的区别.

due to the built-in warnings that Access produces. I'm trying to understand the difference.

如果它们都掩盖了错误,为什么第一个比第二个更可取?这里有什么最佳做法吗?

If they both mask errors, why is the first one preferable over the second? Are there any best practices here?

推荐答案

它们不能同时掩盖错误.DoCmd.SetWarnings 屏蔽错误并且是系统范围的,不限于您正在使用的单个应用程序.DoCmd.SetWarnings False 没有相应的 DoCmd.SetWarnings True 意味着操作查询将在 PC 上的任何 Access 应用程序中运行而没有任何提示.

They do not both mask errors. DoCmd.SetWarnings masks errors and is system wide, not confined to the single application that you are using. DoCmd.SetWarnings False without the corresponding DoCmd.SetWarnings True will mean that action queries will run without any prompts in any Access application on the PC.

Execute 确实会抛出警告,您需要的警告,例如查询无法执行,但不会给出您可能不需要的警告,例如您确定要运行此查询吗".

Execute does throw warnings, the warnings that you need, such as the query failed to execute, but does not give warnings you may not need, such as "Are you sure you want to run this query".

在这个帖子中 Access MVP Allen Browne 说他不使用设置警告.

In this thread Allen Browne, Access MVP, says he does not use Set Warnings.

顺便说一句,我通常建议使用 CurrentDB 的实例,因为这将允许您返回记录计数等,因此:

As an aside, I would generally recommend using an instance of CurrentDB, as this will allow you to return a record count, amongst other things, so:

Set db = CurrentDB
db.Execute sSQL, dbFailOnError

这篇关于DoCmd.SetWarnings 和 CurrentDB.Execute 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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