Articles and Tutorials

Printing a Report

Author: Mike Palmatier
Platform: Visual Basic 6.0

To print a report only a single line of code is needed. The PrintReport method is used to print the currently visible report. A zero 0 is passed in as the only parameter to use the systems default printer.

'Printing using the default printer dialog
wndReportControl.PrintReport 0

You can also use the CommonDialog control to print. With a CommonDialog control, the CommonDialog.hDC property returns a device context for the printer selected in the Print dialog box when the cdlReturnDC flag is set. See the sample below for more on how to do this.

'Printing using the CommonDialog Control
    On Error Resume Next

    With dlgCommonDialog
        .DialogTitle = "Print"
        .CancelError = True
        .Flags = cdlPDReturnDC + cdlPDNoPageNums
        .ShowPrinter
        If Err <> MSComDlg.cdlCancel Then
            wndReportControl.PrintReport .hDC
        End If
    End With

Articles and Tutorials