Print selected report multiple times
Hi,
Using Delphi 6, RB 11.08 Enterprise.
I am using the ReportExplorer to show the user the list of reports they can
run, but I then need to be able to run the selected report multiple times.
The user chooses to log into one or more companies when they run our
software, and I need to print the selected report once for each selected
company. Could be 1, could be any number.
The first instance of report runs as normal, as you'd expect for any report
selected to be printed/previewed from the ReportExplorer. I then have to
reload the report, ask for some company-specific details and run some other
pre-processing (as many reports get their data from tables that are
populated just before the report is generated), before I can automatically
re-run the report for the next company in the list.
I have tried this approach but it isn't working. The slCompanies string list
contains a list of the company number that need reporting on, and is
populated when the user selects the report.
procedure TForm1.ppReport1AfterPrint(Sender: TObject);
begin
{Remove the company from the list and print the next one}
if (slCompanies.Count > 0) then
begin
slCompanies.Delete(0);
if (slCompanies.Count > 0) then
begin
ppReport1.Reset;
CurrentCompany := StrToInt(slCompanies[0]); {Global variable used to
set a parameter in the report elsewhere}
OpenReportAtCurrentRecord; {Loads the template, runs pre-processing
and sets any parameters}
ppReport1.AfterPrint := ppReport1AfterPrint; {Reattach event as this
is not present on the report template}
ppReport1.Print;
end;
end;
end;
Remember, the first report has printed OK. Next, the report is reloaded, the
pre-processing happens, the parameters are filled in - this all happens
successfully - but the Print then does nothing, whether I choose Screen,
Printer or any other output Device.
Obviously the AfterPrint event is not the best place for this, but I can't
see where else I know that the report has finished and I am ready to print
it again. The ReportExplorer and the Designer don't have the events (as far
as I can see) to let me know when things have happened at the appropriate
time.
Any suggestions would be useful.
Thanks,
Jason.
--
Jason Sweby
Software Development Manager,
Carval Computing Limited, Plymouth, UK
Payroll - HR - T&A - Access Control
Using Delphi 6, RB 11.08 Enterprise.
I am using the ReportExplorer to show the user the list of reports they can
run, but I then need to be able to run the selected report multiple times.
The user chooses to log into one or more companies when they run our
software, and I need to print the selected report once for each selected
company. Could be 1, could be any number.
The first instance of report runs as normal, as you'd expect for any report
selected to be printed/previewed from the ReportExplorer. I then have to
reload the report, ask for some company-specific details and run some other
pre-processing (as many reports get their data from tables that are
populated just before the report is generated), before I can automatically
re-run the report for the next company in the list.
I have tried this approach but it isn't working. The slCompanies string list
contains a list of the company number that need reporting on, and is
populated when the user selects the report.
procedure TForm1.ppReport1AfterPrint(Sender: TObject);
begin
{Remove the company from the list and print the next one}
if (slCompanies.Count > 0) then
begin
slCompanies.Delete(0);
if (slCompanies.Count > 0) then
begin
ppReport1.Reset;
CurrentCompany := StrToInt(slCompanies[0]); {Global variable used to
set a parameter in the report elsewhere}
OpenReportAtCurrentRecord; {Loads the template, runs pre-processing
and sets any parameters}
ppReport1.AfterPrint := ppReport1AfterPrint; {Reattach event as this
is not present on the report template}
ppReport1.Print;
end;
end;
end;
Remember, the first report has printed OK. Next, the report is reloaded, the
pre-processing happens, the parameters are filled in - this all happens
successfully - but the Print then does nothing, whether I choose Screen,
Printer or any other output Device.
Obviously the AfterPrint event is not the best place for this, but I can't
see where else I know that the report has finished and I am ready to print
it again. The ReportExplorer and the Designer don't have the events (as far
as I can see) to let me know when things have happened at the appropriate
time.
Any suggestions would be useful.
Thanks,
Jason.
--
Jason Sweby
Software Development Manager,
Carval Computing Limited, Plymouth, UK
Payroll - HR - T&A - Access Control
This discussion has been closed.
Comments
would be useful here. I use that event to override the behaviour of what
happens when the user selects a report to be loaded, but I cannot then stop
it from performing whatever action the user selected in the ReportExplorer.
Can I? (Without having to create a custom ReportExplorer).
Thanks,
Jason.
I have a few questions about what you are trying to accomplish.
1. Are you certain the Report.AfterPrint event is firing? If you are
loading templates from the ReportExplorer, you need to re-assign all event
handlers using the Template event OnLoadEnd or they will be ignored.
2. Once your users select a report, do they have the option to view each
report or do you simply want to automatically print each report to
printer/file?
3. I don't believe you will need to replace the ReportExplorer but it may be
worth trying to replace the Explorer form (ppExpFrm.pas) with a custom copy
that perhaps performs a batch print rather than a single print job for the
Print and PrintPreview routines. This would most likely be more robust that
trying to print from the AfterPrint event.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for responding.
1. Yes, I am certain the AfterPrint event is firing. I am reattaching that
event after the template reloads, and everything within it is happening
except that subsequent reports never actually appear (whether printed,
emailed or previewed).
2. Once the user selects a report, they are asked for all the details
pertaining to that report again, as any parameters used for the first
company may not be relevant to the second and subsequent companies. They are
also asked for the print destination again (Printer, Window, etc). This is
all happening, the relevant dialogs appear, but, as I said above, the report
never gets printed.
How do I access the Template OnLoadEnd event? Does this have to set in code?
Jason.
Thanks for the information.
The way I understand it, this is what happens so far.
1. The user selects a report.
2. They are then asked for details about the report.
3. The report previews/prints.
This is where I'm confused. After the report prints, do you want to ask the
user the same questions over again to print another report? How will your
application know how many reports it needs to print?
Either way, the native Report Explorer was not designed to handle this type
of operation. I would highly recommend that you consider replacing the
Explorer form with a custom one that alters the correct routines to print
multiple versions of the same report in sequential order.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for the responses, I know this isn't a straight forward scenario. The
situation is that the user selects a report to print, and then I need it to
be run once for each company that the user has selected way back when they
started up our software. They get to multi-select from a list of companies.
It isn't simply a case of running the report once with a selection criteria
that allows all companies to be reported on at once, because each one will
need pre-processing first. And any parameter values that are set for Company
1 (e.g. "Financial Year", or "From Employee Number" and "To Employee
Number") may not be appropriate values when the report is run for Company 2.
I know up front how many companies the user selected when they logged in,
and that number is the number of times the report needs to go through the
loop of:
1. Ask the user where they want to print to
2. Ask the user to populate any Report parameters (i.e. auto-search values)
3. Run any pre-processing so that the correct data is on some tables ready
for the report to display
4. Print/Preview/Email/Export the report.
I've not looked into customising the ReportExplorer form yet and was hoping
to avoid such a measure, but if the native component was not designed to
handle this then I may well have to investigate further.
Thanks,
Jason.