How to show progress on status bar when running a sequence of queries in MS Access

烈酒焚心 提交于 2019-12-04 15:51:42

Just now stumbled upon this so it's most likely too little, too late, but be sure that during every iteration, after you change the status bar you call DoEvents. This tells your procedure to return control to the application and Windows for a second, which is how it changes that status bar text. It's also how you keep Access from looking to Windows like it's not responding.

Zajonc

Thanks to the help I received from HansUp in answering a similar question (How to show progress on status bar when running code (not queries)) which I posted afterwards, I can now answer this question myself.

To make the code work without the call to MsgBox, you need to put two lines before the call to Application.Echo:

RetVal = SysCmd(4, "Executing " & QueryName & " ...")
DoEvents

This now does exactly what I want.

Corresponding to @Zajonc's comment to Hauns TM answer.

It happens, because ot this line:

RetVal = SysCmd(5)

This means: refresh statusbar.

More about status bar in MS Access: ACC: How to Change the Status Bar Text Using SysCmd()

So, till first procedure works, do not refresh status bar ;)

For i = 1 to 10
    SysCmd(4, "Running query " i & " of " & 10)
    'your code here...
    RunQueryAndReportStatusWithMsgBox(...)
Next
'here you should refresh status bar ;)

Cheers,
Maciej

I'm not sure that this is what you are looking for? Maybe:

Dim statusText As String
Dim statusPercent As Integer

statusText = "Yada yada..."
statusPercent = 100 / 500 * 100

Application.StatusBar = "Progress: " & statusText & "(" & Cstr(statusPercent) & " %)" 'Progress: Yada yada... (20 %)

I.e. change the assignment in Application.StatusBar everytime you want it to change.

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