ms-access - how to automatically select yes in warning message boxes

走远了吗. 提交于 2020-01-16 15:46:33

问题


in ms-access i am running a macro that runs several queries, during the execution of a query a message box appears

"you are about to run an update.......... are you sure you want to run this query ? "

how can i automatically select for all such cases so that macro runs without human intervention.


回答1:


You can turn off temporary the warnings like this:

DoCmd.SetWarnings = False
DoCmd.RunSQL ...
DoCmd.SetWarnings = True



回答2:


It is generally best to use Execute in such cases in order to trap errors:

Dim db As Database, qdf As QueryDef, strSQL As String

Set db = CurrentDb
Set qdf = db.QueryDefs("Query17")
qdf.Execute dbFailOnError
Debug.Print qdf.RecordsAffected

Or

strSQL="UPDATE SomeTable SET SomeField=10"
db.Execute strSQL, dbFailOnError
Debug.Print db.RecordsAffected

Trapping errors with dbFailOnError and an error trap is more or less essential and there are a number of other useful aspects to the Execute Statement




回答3:


To avoid having to write the code @Remou supplies every time you execute arbitrary SQL you could use my SQLRun function, which is designed as a dropin replacement for DoCmd.RunSQL and avoids all the problems therewith.



来源:https://stackoverflow.com/questions/1872554/ms-access-how-to-automatically-select-yes-in-warning-message-boxes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!