问题
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