我在Windows 7中的MS Access 2010中有一个宏,它运行一系列相当慢的Make Table和Update查询。我希望它显示在状态栏上查询它正在运行,因为通常的消息“运行查询”不会给出查询名称。如何在MS Access中运行一系列查询时在状态栏上显示进度
我已经写以下VBA:
Function RunQueryAndReportStatusWithMsgBox(QueryName As String)
Dim RetVal As Variant
On Error GoTo ErrHandler
PutStatusBarBack
MsgBox "About to run query"
Application.Echo False, "Executing " & QueryName & " ..."
DoCmd.OpenQuery QueryName, acViewNormal, acEdit
On Error GoTo 0
Exit Function
ErrHandler:
Select Case Err
Case 2501: ' OpenQuery cancelled by the user pressing escape
MsgBox "The OpenQuery action for query " & QueryName & " was cancelled by the user."
Case Else: ' Another error has occurred.
' Display the error number and the error text.
MsgBox "Error # " & Err & " : " & Error(Err)
End Select
' Put status bar back to normal.
PutStatusBarBack
End Function
Function PutStatusBarBack()
Dim RetVal As Variant
On Error GoTo ErrHandler
' Put status bar back to normal.
RetVal = SysCmd(5) ' not sure if I need this.
Application.Echo True, ""
On Error GoTo 0
Exit Function
ErrHandler:
' Display the error number and the error text.
MsgBox "Error # " & Err & " : " & Error(Err)
' Put status bar back to normal.
RetVal = SysCmd(5) ' not sure if I need this.
Application.Echo True, ""
End Function
我已经写了宏调用RunQueryAndReportStatusWithMsgBox
与依次在每个查询作为参数,然后我打电话PutStatusBarBack
在宏观的末尾。我在开始时和结束时关闭警告。这很好 - 就像我想要的一样。
但是,我不想在每次查询开始时在消息框上按OK。如果我注释掉MsgBox
声明,它就不再起作用了。结果是可变的。有时它会在状态栏中显示某些内容,有时不显示。当我刚刚运行它时,我只是收到了“准备好”的消息,但有时候我已经得到了所需的消息,但并非所有的查询都出现了。
我试过使用RefreshDatabaseWindow
而不是MsgBox
,但这没有什么区别。
感谢您的建议Hans TM。不幸的是Access不理解Application.StatusBar。我最初尝试了RetVal = SysCmd(4,“Executing”&QueryName&“...”),但状态栏被Access覆盖,并显示“运行查询”。 – Zajonc 2015-01-04 13:11:14