ClearMacroError 宏操作
适用于:Access 2013、Office 2013
可以使用 ClearMacroError 操作清除有关 MacroError 对象中所存储的错误的信息。
Setting
ClearMacroError 操作不具有任何参数。
备注
宏错误时,错误的信息存储在 MacroError 对象。 如果尚未使用 OnError 操作禁止显示错误消息,则宏将停止,错误信息将显示在标准错误消息中。 但是,如果已使用 OnError 操作来禁止显示错误消息,则可能需要在条件或自定义错误消息中使用 MacroError 对象中存储的信息。
在错误得到处理后, MacroError 对象中的信息将过期,因此最好使用 ClearMacroError 操作清除该对象。 执行此操作会将 MacroError 对象的错误数量重置为 0,并清除有关存储在该对象中的错误的所有其他信息,例如错误说明、宏名称、操作名称、条件和参数。 通过这种方式,可在以后重新检查 MacroError 对象,以确定是否发生了其他错误。
在任何宏结束时,都会自动清除 MacroError 对象,因此无需在宏末尾使用 ClearMacroError 操作。
MacroError 对象每次仅包含有关一个错误的信息。 如果宏中发生了多个错误, MacroError 对象将仅包含有关最后一个错误的信息。
要在 VBA 模块中运行 ClearMacroError 操作,请使用 DoCmd 对象的 ClearMacroError 方法。
示例
The following macro uses the OnError action with the Next argument to suppress error messages, and then uses the OpenForm action to open a form. For this example, an error is deliberately created by using the GoToRecord action to go to the previous record. The condition [MacroError].[Number]<>0 tests the MacroError object. If an error has occurred, the error number is non-zero, and the MessageBox action runs. The message box displays the name of the action that caused the error (in this case, the GoToRecord action), and the error number is displayed. 此示例最后运行 ClearMacroError 操作清除 MacroError 对象。
条件 |
操作 |
参数 |
---|---|---|
OnError |
转至:“下一个” |
|
OpenForm |
窗体名称:CategoryForm视图: FormWindow 模式: 普通 |
|
GoToRecord |
对象类型: FormObject 名称:CategoryFormRecord:Previous |
|
[MacroError]。[数字]<>0 |
MessageBox |
消息: =“Error # ” & [MacroError]。[Number] & “ on ” & [MacroError]。[ActionName] &“action”。蜂鸣声: 是类型:信息 |
ClearMacroError |