How to stop a report from printing from the preview.

Here is a question for the gurus.

Certain reports in NAV do not allow the Print option to be called from the Preview screen. For example report 206 - Sales - Invoice will show the message “This report cannot be printed from Print Preview. Quit Print Preview and run the report” if you try to preview the report and then click File/Print.

I understand why this is done - since we want to update the printed count against the document and we can only do this if the document is actually sent to the printer since no programming code executes when you select the Print option after previewing a document.

My question is, how is this behaviour controlled?

I have looked on the properties for the report and cannot find anything that looks like it would do this. I made a copy of the report and the new report does the same - so that suggests to me it is something in the report object itself.

Can anyone enlighten me?

[:’(]

Hi Gaspode,

This behavior is controlled not through properties, but indirectly through code.

If somewhere in the report you test for wether or not the report is in preview-mode or not, by using IF CurrReport.PREVIEW THEN, that will cause this behavior.
In report 206 you’ll find 2 places where this is tested.

  • Sales Invoice Header - OnAfterGetRecord
  • CopyLoop - OnPostDataItem.
    Remove theese, and you’ll be able to print report 206 from the preview-window.
    Other way around, put a line of code like that in your report, and you’ll end up with a report that can’t be printed from the preview-window.

Hi Alexander,

Great spot - doesn’t even tell you in the help of this “side-effect” [Y]