简体   繁体   English

使用 VBA 确保在 Microsoft Access 数据库上进行同步 SQL 查询调用

[英]Ensure synchronous SQL query calls on a Microsoft Access database with VBA

I have a vba script that loops through several update queries performed on a table in Microsoft Access.我有一个 vba 脚本,它循环执行对 Microsoft Access 中的表执行的多个更新查询。

Should i use CurrentDb.Execute or DoCmd.RunSQL to ensure that the update queries are run sequentially and do not get ahead of each other?我应该使用 CurrentDb.Execute 还是 DoCmd.RunSQL 来确保更新查询按顺序运行并且不会彼此领先?

Essentially,本质上,

Do Until Counter = 7

CurrentDb.Execute "sql_update1"
CurrentDb.Execute "sql_update2"
CurrentDb.Execute "sql_update3"

Counter = Counter + 1
Loop

I want to make sure that sql_update2 does not start running until sql_update1 is finished as sql_update2 relies on what sql_update1 did.我想确保 sql_update2 在 sql_update1 完成之前不会开始运行,因为 sql_update2 依赖于 sql_update1 所做的事情。

.. ensure that the update queries are run sequentially ..确保更新查询按顺序运行

VBA is single-threaded, so it can only run the queries - and any other code - sequentially. VBA 是单线程的,因此它只能按顺序运行查询和任何其他代码。

You will need a call to an external process to obtain something to run asynchronously.您将需要调用外部进程来获取异步运行的内容。 Shell is typically used for that. Shell通常用于此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM