问题描述
在对的评论中,Remou写道:
In the comments on this answer, Remou writes that
CurrentDB.Executeinsert sql here
比
DoCmd.SetWarnings = 0
DoCmd.RunSQLinsert sql here
由于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
将意味着操作查询将在任何Access中都没有任何提示运行应用程序在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".
在这个主题中,Allen Browne,Access MVP说他不使用Set Warnings。
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有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!