取消报告打印后如何抑制错误消息? [英] How to suppress error message after cancel report print?

查看:34
本文介绍了取消报告打印后如何抑制错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 DoCmd.RunCommand acCmdPrint 打印报告.如果我打印报告,好的.但如果我取消,Access 会显示错误并停止运行按钮代码.

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.

我使用了 DoCmd.SetWarnings (False) 但不要抑制这个错误.

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

我该怎么办?

推荐答案

您需要检查错误处理程序中的错误代码,如果是操作已取消",则忽略它.

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

这篇关于取消报告打印后如何抑制错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆