gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:34:14 34 4
gpt4 key购买 nike

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 应用程序中运行而没有任何提示。

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

In this thread Access MVP Allen Browne 说他不使用设置警告。

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

Set db = CurrentDB
db.Execute sSQL, dbFailOnError

关于sql - DoCmd.SetWarnings 和 CurrentDB.Execute 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11213892/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com