locked
Unable to trap cancelling a pdf print using print dailog RRS feed

  • Question

  • Hi Smart people,

    I use error trapping for error 2501 in all my print or email vba procedures but now I've come up against a scenario that I can't seem to trap.

    From my MainForm I open another form in dialog mode to determine where my report is going, ie email, screen or printer. The print code on this form is:

        If Option1.value = True Then
            PrintAReportShowingPrintDialog stDocName
        End If

    The Module called has the following code:

    Public Sub PrintAReportShowingPrintDialog(ByVal strReportName As String)
    On Error GoTo Handle_Error

    With DoCmd
            .Hourglass True
            .OpenReport strReportName, acViewPreview, , , acIcon
            .RunCommand acCmdPrint
            .SelectObject acReport, strReportName, True
            .Hourglass False
    End With

    When Print Dialog window opens & Cancel is selected, the error 2501 is trapped successfully, however if OK is selected & the File Save window appears to save pdf file, choosing cancel does not cause the error 2501 to be trapped.

    Any ideas on how to get that trapped at this point?

    Thursday, November 24, 2011 2:06 PM

Answers

  • I can suggest a work around -

    Open a file dialog and get the user to select a file name and location.

    You can detect if they cancel as the dialog should return an empty string.

    Then print the pdf to the path specified

    you can then shell out to the pdf for them to view the pdf.

    You may need to juggle the logic. eg offer them a cancel after they view the pdf which will delete it.

    Have a think about the sequence you could use and post back if you need any code.


    Kent
    • Marked as answer by Bruce Song Wednesday, December 7, 2011 10:48 AM
    Saturday, November 26, 2011 6:07 AM