Partilhar via


Controlling Report and Label Output

You can control where report and label output is sent by using one of these keywords with the REPORT or LABEL command:

  • PRINT
  • PREVIEW
  • FILE

If you don't use any keywords, the report is sent to the screen or active window.

Selecting Records to Print

When you print a report, you might want to limit the number of records that appear in the report by providing selection criteria. You can:

  • Choose a scope of records by specifying a quantity or range.
  • Build a FOR expression that selects records that match a condition.
  • Build a WHILE expression that selects records until one record is found that doesn't match a condition.

You can use any combination of these options. The WHILE expression overrides the other criteria.

Printing a Quantity or Range of Records

One way you can limit the number of records is to specify a quantity or range of records. Using the Scope option, you can select a single record or a group of records positioned sequentially in the file.

Note   The active index and the current record pointer affect the results of the scope options Next and Rest. For example, the next record in a table indexed by last name is probably different than one in a table indexed by state. This doesn't affect the Record option because the number for a record doesn't change when the table is indexed.

To select a limited number of records

  1. From the File menu, choose Print.

  2. In the Print dialog box, choose Options.

  3. In the Print Options dialog box, choose Options.

  4. In the Print and Label Print Options dialog box, choose Scope.

  5. Select the appropriate scope option.

    To print Choose this scope option
    Every record from the source file ALL
    A range of records starting with 1 NEXT
    A specific record by number RECORD
    The current record plus all of those after it to the end of the file REST

    Visual FoxPro prints the report using data from the records within the scope you selected.

Printing Records That Match a Condition

If the records you want to select are not sequential within the table, you can build a logical expression that specifies selection criteria a record must meet to be printed. For example, you can choose to print all records with a particular value in a field.

To enter criteria for selecting records

  1. From the File menu, choose Print.

  2. In the Print dialog box, choose Options.

  3. In the Print Options dialog box, choose Options.

  4. In the Print and Label Print Options dialog box, choose Scope.

  5. In the For box, enter a FOR expression.

    -or-

    Make sure the records sources used by the report are open, and then choose the For button to use the Expression Builder.

    Note   You don't need to include the FOR command in the expression. For example, type country = "Canada" to see only Canadian data.

    Visual FoxPro evaluates all of the records and prints the report using those records that match the condition in the expression.

Controlling Selection of Records to Print

When printing, you can specify a condition that must be met to continue evaluating and selecting records. You enter this condition as a WHILE expression. As long as the WHILE expression remains true, Visual FoxPro processes the data source. After finding a record that doesn't meet the condition, Visual FoxPro ends the evaluation process and prints the selected records. This option allows you to select records based on information outside the values contained in the fields.

Tip   If you use a WHILE expression on a file that hasn't been indexed, the selection process may end before evaluating all of the appropriate records. Before printing the report, be sure the source table has the appropriate index active for the WHILE expression you want to use.

To enter criteria for ending record selection

  1. From the File menu, choose Print.

  2. In the Print dialog box, choose Options.

  3. In the Print Options dialog box, choose Options.

  4. In the Print and Label Print Options dialog box, choose Scope.

  5. In the While box, enter a WHILE expression.

    -or-

    Choose the While button to use the Expression Builder.

    Note   You don't need to include the WHILE command in the statement. For example, type sales > 1000 to see only sales above one-thousand dollars.

    Visual FoxPro prints the report using the records it evaluates while the expression is true.

Printing Reports and Labels

If you want to send the report to the printer, you can send it directly to the printer or display the Print Setup dialog box.

To send a report to the printer

  1. From the File menu, choose Print.

  2. Choose OK.

    Note   If the data environment is not set, the Open dialog box appears with a list of tables from which you can select.

    Visual FoxPro sends the report to the printer.

    -or-

  • Use the TO PRINTER clause of the REPORT or LABEL command.

For example, the following code sends the report MyReport to the default printer and stops the report from printing on the screen:

REPORT FORM MYREPORT.FRX TO PRINTER NOCONSOLE

To display the Print Setup dialog box before sending the report to the printer

  • Use the TO PRINTER PROMPT clause of the REPORT or LABEL command.

For example, the following code displays the Print Setup dialog box, sends the report MyReport to the default printer, and stops the report from printing in the active window:

REPORT FORM MYREPORT.FRX TO PRINTER PROMPT NOCONSOLE

Previewing Reports and Labels

If you want to display a preview of the report, you can send it to the Preview window in the Report Designer. The Preview window has its own toolbar with buttons that move you from page to page in the report.

Caution   If you get the prompt, "Do you want to save changes to your file?", you have selected to close not just the Preview window, but also the layout file. You can select Cancel to return to Preview mode or Save to save your changes and close the file. If you select No, any changes you made to the layout will not be saved.

To preview a report

  1. From the View menu, choose Preview.

  2. In the Print Preview toolbar, choose Previous Page or Next Page to switch pages.

  3. To change the size of the report's image, choose Zoom.

  4. To print the report, choose Print.

  5. To return to design mode, choose Close Preview.

    -or-

  • Use the PREVIEW clause of the REPORT command

For example, the following code displays the report in a modal window:

REPORT FORM MYREPORT.FRX PREVIEW

By default, the Preview window is modal but allows access to the Preview toolbar. If you want to make the preview modeless, you can add the keyword NOWAIT to the REPORT command.

For example, the following code displays the report in a modeless window:

REPORT FORM MYREPORT.FRX PREVIEW NOWAIT

If you want to preview the results in a specific window, you can include the WINDOW clause to specify a window created with DEFINE WINDOW.

REPORT FORM MYREPORT.FRX PREVIEW WINDOW MYWINDOW

Printing Reports to File

If you want to create an electronic version of the report, you can send it to a file formatted for your printer or to an ASCII file. Sending reports to a file allows you to print them in a batch on your printer at a later time.

If you want to create an ASCII file, you can create a file that includes only the text, dashes, and plus signs to represent lines and shapes. Font and color choices are not included. You can also specify the number of characters to place on each line and the number of lines to place on each page.

To print a report to an ASCII file

  • Use the FILE and ASCII keywords of the REPORT command.

The following example defines the variables for the ASCII page, then prints a report called Myreport.frx to an ASCII file name Myfile.txt.

Printing to an ASCII File  
Code Comment
_asciirows = nLines
Define the number of lines per page.
_asciicols = nChars
Define the number of characters per line.
REPORT FORM MYREPORT.FRX
  TO FILE MYFILE.TXT ASCII
Run the report.

See Also

Setting Print Options for Groups | Saving a Report as HTML | Adding Reports and Labels | SELECT - SQL