【发布时间】:2015-01-04 12:14:48
【问题描述】:
我在 Windows 7 的 MS Access 2010 中有一个宏,它运行一系列非常慢的 Make Table 和 Update 查询。我希望它在状态栏上显示它正在运行的查询,因为通常的消息“运行查询”没有给出查询名称。
我已经编写了以下 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,但这没有任何区别。
【问题讨论】:
标签: ms-access vba ms-access-2010 statusbar