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

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

问题描述

在上这个答案的意见,Remou写道:

In the comments on this answer, Remou writes that

CurrentDB.Execute插入SQL这里

DoCmd.SetWarnings = 0
DoCmd.RunSQL插入SQL这里

DoCmd.SetWarnings = 0
DoCmd.RunSQL "insert sql here"

由于该访问产生的内建的警告。我试图理解上的差异。

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

如果他们都屏蔽错误的,为什么是第一个preferable在第二?是否有任何的最佳做法吗?

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

推荐答案

他们不都面膜错误。 DoCmd.SetWarnings掩盖错误,是全系统的,并不仅仅局限于你所使用的单个应用程序。 DoCmd.SetWarnings假没有相应的 DoCmd.SetWarnings真将意味着操作查询将运行没有任何访问任何提示应用在PC上。

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 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".

在这个线程艾伦·布朗,访问MVP,说他不使用套装警告。

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天全站免登陆