sql – DoCmd.SetWarnings和CurrentDB.Execute有什么区别?

在对 this answer评论中,Remou写道

CurrentDB.Execute“insert sql here”

比以前好

DoCmd.SetWarnings = 0
DoCmd.Runsql“insert sql here”

由于Access产生的内置警告.我想了解这个区别.

如果他们都掩盖错误,为什么第一个比第二个更好?这里有最好的做法吗?

解决方法

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

执行会抛出警告,您需要的警告,例如查询执行失败,但不会提供您可能不需要的警告,例如“您确定要运行此查询”.

Access MVP的Allen browne说,他并没有使用Set Warnings.

除此之外,我通常会建议使用CurrentDB的一个实例,因为这将允许您返回记录计数,除此之外:

Set db = CurrentDB
db.Execute ssql,dbFailOnError

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...