vba 如何减慢 MS-Access 中宏的执行速度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11620001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I slow down the execution of a macro in MS-Access
提问by talbright
I have a macro in MS-Access that only runs correctly half the time on one computer, but when tested on another computer it runs 100% of the time.
我在 MS-Access 中有一个宏,它在一台计算机上只能正常运行一半的时间,但在另一台计算机上测试时它运行 100% 的时间。
I suspect that this is because the macro is running to fast, and not finishing the execution of one step before it moves to the next one. Is there a way I can pause between steps?
我怀疑这是因为宏运行速度太快,并且在移动到下一个步骤之前没有完成一个步骤的执行。有没有办法在步骤之间暂停?
The steps for my macro are as follows:
我的宏的步骤如下:
- RunCode for Import-Data
- Open Append Query
- Open Append Query
- Open Update Query
- RunSQL for Delete-Data
- 导入数据的运行代码
- 打开追加查询
- 打开追加查询
- 打开更新查询
- 用于删除数据的 RunSQL
The first step and the last step execute 100% of the time on both computers, but the middle steps sometimes fail with no error. I have tried to add this code between the macro to slow it down. I can't figure out how to apply it correctly, or if this solution is even correct.
第一步和最后一步在两台计算机上都执行 100% 的时间,但中间步骤有时会失败且没有错误。我试图在宏之间添加此代码以减慢它的速度。我不知道如何正确应用它,或者这个解决方案是否正确。
Public Function SlowMacro()
Application.Wait (Now + TimeValue("0:00:02"))
End Function
Any help is appreciated, Thanks in advance.
任何帮助表示赞赏,提前致谢。
采纳答案by HansUp
If you want your SlowMacro()
function to cause a 2 second pause, you can use code from the Access Web: API: Make code go to Sleep
如果您希望您的SlowMacro()
函数导致 2 秒的暂停,您可以使用来自 Access Web 的代码:API:使代码进入睡眠状态
Then I think this should work as your function.
然后我认为这应该作为您的功能。
Public Function SlowMacro()
sSleep 2000
End Function
These are the key pieces from that web page I linked.
这些是我链接的那个网页的关键部分。
Private Declare Sub sapiSleep Lib "kernel32" _
Alias "Sleep" _
(ByVal dwMilliseconds As Long)
Sub sSleep(lngMilliSec As Long)
If lngMilliSec > 0 Then
Call sapiSleep(lngMilliSec)
End If
End Sub