Visual Basic Concepts

Printing a Data Report

See Also

Printing a data report can be accomplished in one of two ways. The user can click the Print button that appears on the data report in Print Preview mode (using the Show method), or you can programmatically enable printing using the PrintReport method. If an error occurs during printing, trap it in the Error event.

For More Information   See "Data Report Events."

Choosing to Display a Print Dialog Box

When printing a report programmatically, you have two choices: to print by displaying the Print dialog box, or by printing without displaying the dialog box.

To display the Print dialog box

  1. Add a CommandButton to a Form.

  2. In the button's Click event, place the following code:
    DataReport1.PrintReport True
    

The Print dialog box allows the user to select a printer, print to file, select a range of pages to print, and specify the number of copies to print.

Note   Printers must be installed on the computer in order to present a choice of printers.

Printing Without a Dialog Box

In some cases, you may wish to print the report without user intervention. The PrintReport method also gives you the option of selecting a range of pages to print, either all, or a specified range.

To print without displaying the dialog box

  1. Add a CommandButton to a Form.

  2. In the button's Click event, place the following code:
    DataReport1.PrintReport False
    

    Or, to specify a range of pages to print, use the code below:

    DataReport1.PrintReport False, rptRangeFromTo, 1, 2