Close report preview from code
I am running a series of reports, monthly reports with the as of date changing. (When the data is obtained and calculated for each report date, I save it in a historical database, which is outside of RB). Since the same data calcs are used to display reports that go into the history DB, it is very handy to do both at the same time (looping the as of date).
This works very well, but is inconvenient for the user to have to close each report before the next report is run. I have tried closing the report using the "Cancel" event in the AfterPrint event and a few other places, but the previewed report sits on the screen until the user closes it, then proceeds to the next report in the loop. I am thinking if I print the report to a file, that may work, but it is nice for the user to see the report even briefly on the screen as an assurance the monthly reports and calcs were done.
Scott S.
This works very well, but is inconvenient for the user to have to close each report before the next report is run. I have tried closing the report using the "Cancel" event in the AfterPrint event and a few other places, but the previewed report sits on the screen until the user closes it, then proceeds to the next report in the loop. I am thinking if I print the report to a file, that may work, but it is nice for the user to see the report even briefly on the screen as an assurance the monthly reports and calcs were done.
Scott S.
Comments
If you are just previewing, try using the Viewer.OnEndGenerate to determine when the report has been fully generated. Then make a call to Report.PreviewForm.Close. If you are exporting to a file or printing, the AfterPrint event should work with the same code. Something like the following...
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I get to the line to close the preview form, but then then the loop to re-print the report hangs up after that. Originally I was calling ppReport2.Print, with the output to Screen, and have the AfterPrint event sending summed up data to the database. Without automatic closing, the user has to close the form manually and the loop re-runs the report with new as of date.
I don't see that I could call ppRepport2.Preview if that was one of your options. Since I would just as soon call ppReport2.Print, with its AfterPrint event anyway, I tried your code:
Sleep(1000);
ppReport2.PreviewForm.Close;
at the end of the AfterPrint event, but that did not work either?
Scott
I sent you an example of this working. I am not getting the "hanging" that you are for my example.
There is no such call as Report.Prevew. This would be Report.Print with the DeviceType equal to Screen.
When previewing, the AfterPrint event fires once the preview form is closed so trying to close the form in that event will not work.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com