How to suppress error message after cancel report print?

时光总嘲笑我的痴心妄想 提交于 2021-01-29 17:15:34

问题


I used DoCmd.RunCommand acCmdPrint to print a report. If I print the report, ok. But if I cancel, Access show a error and stop run the button code.

I used DoCmd.SetWarnings (False) but don't suppress this error.

How can I do?


回答1:


You need to check the error code in your error handler, and if it's "Operation cancelled", ignore it.

Option Explicit

Sub Something()
    On Error GoTo Trap

    'DoCmd...

Leave:
    On Error GoTo 0
    Exit Sub

Trap:
    If Err.Number <> 2501 Then MsgBox Err.Description, vbCritical
    Resume Leave
End Sub


来源:https://stackoverflow.com/questions/60062481/how-to-suppress-error-message-after-cancel-report-print

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