JavaScript Editor js editor     Web development 

Main Page

Occurs when the user closes a report preview or opts to print from a report preview.




Specifies whether the user indicated a desire to print the pages in the current output page set after closing the report preview.

Return Value



Applies To: ReportListener Object.

The PreviewContainer API specifies that, when the user closes a report preview form, the PreviewContainer must call the ReportListener’s OnPreviewClose method. When the user chooses to print from Preview, Preview calls OnPreviewClose with an argument of True (.T.).

The ReportListener invokes the PreviewContainer's SetReport method in OnPreviewClose with an argument of NULL (.NULL.). At this time, the ReportListener can choose to set its PreviewContainer reference to NULL (.NULL.) or retain it. However, cccording to the conventions of the PreviewContainer API, it is the responsibility of PreviewContainer to remove its back reference to the ReportListener at this time. For more information, see The Preview Container API and PreviewContainer Property.

If the user opted to print from preview, the print run starts after this method finishes. The print run uses cached pages prepared for preview at this point, so the available output exactly matches what the user saw in preview, including any RANGE or scope specifications included in the REPORT FORM command that invoked the preview.

If the ReportListener's CommandClauses.Prompt value is True (.T.) at this point, the printer setup dialog appears before the print run. The user may alter the specifications with which the report prints. This value may be True for one of the following reasons:

  • You used the PROMPT clause on the original REPORT FORM command.

  • The PreviewContainer or ReportListener adjust the CommandClauses.Prompt value dynamically.

The pages that print are not always the full range of available output pages; they may be some subset of this range. Fewer than the full number of output pages may print for one of the following reasons:

  • The user adjusts the page range in the PROMPT dialog.

  • The PreviewContainer or ReportListener adjusts the ReportListener CommandClauses members provided for the purpose of limiting printed output from the OnPreviewClose method. These members are PrintPageCurrent, PrintRangeFrom, and PrintRangeTo. For more information, see CommandClauses Property.

If you use NOPAGEEJECT to combine multiple reports within a single report run, the value of CommandClauses.Prompt is only significant at the moment the PreviewContainer invokes the print run. If you have not dynamically adjusted its value, the value of CommandClauses.Prompt has therefore been determined by whether the final REPORT FORM command in the report run included the PROMPT clause.

Because the printer setup dialog appears after the report has been rendered, in response to CommandClauses.Prompt, and because the report was rendered with information gathered from the printer set earlier, there is some potential for a mismatch between the previously-rendered report and the instructions set by the user in the dialog. For example, the printer chosen in the dialog might have a different printable page size than the original printer. The printed results in this scenario are determined by the way the chosen printer's driver chooses to handle this page size instruction.


You can alter the various dynamic members of CommandClauses during the OnPreviewClose method, to print complex page ranges. In the following code sketch, a derived ReportListener provides a custom dialog to gather a complex page range from a user, and then invokes the native behavior multiple times to print the various page ranges requested by the user.

В Copy Code
PROCEDURE OnPreviewClose(lPrint)
   LOCAL liRange
   IF lPrint
      IF NOT EMPTY(THIS.CommandClauses.PrintPageCurrent
         *user chose "print current page" option from PreviewContainer.
         *Print only that page:
         THIS.CommandClauses.PrintRangeFrom = ;
         THIS.CommandClauses.PrintRangeTo = ;
         THIS.CommandClauses.Prompt = .F.
         IF EMPTY(THIS.PageRangeArray[1])  
            * no printing is requested
            * user chose at least one range;
            * go through the array set up by 
            * the dialog and print the range(s)
            FOR liRange = 1 TO (ALEN(THIS.PageRangeArray,1))
               THIS.CommandClauses.PrintRangeFrom = ;
               THIS.CommandClauses.PrintRangeTo = ;

See Also

JavaScript Editor js editor     Web development