*-- Initialize variables PRIVATE plPhantom, plPrinted, pnPages, pcTemp plPrinted = .f. pnPages = 0 pcTemp = SUBSTR(SYS(2015), 3, 10) + '.txt' *-- Prompt for printer = SYS(1037) *-- Print the phantom report WAIT WINDOW 'Calculating Page Count...' NOWAIT plPhantom = .t. REPORT FORM MyReport NOCONSOLE TO FILE &pcTemp pnPages = _PAGENO ERASE (pcTemp) plPhantom = .f. WAIT CLEAR *-- Print the real report IF plPrinted REPORT FORM MyReport TO PRINTER PROMPT PREVIEW ENDIFIn the OnExit Expression of the Report Summary, enter the following code:
_VFP.SetVar('plPrinted', .t.)This confirms that the report wasn't canceled by the user while processing the first phantom print. It's also important that you prompt for the printer up front so you can be assured that the same printer driver is used in the phantom print as the real print. Otherwise, you could have different unprintable margins .. which means different page counts!!