LoadFromDatabase depending on result set column value
Situation:
I would like to be able to load a template in ppReport1 depending on a field
value in the pipeline. For example, my result set has a column called
'REP_NAME' that has values of a 0 or 1. If the value of the column is a 0,
I would like ppReport1 to use a template called 'REPA'. If the value of the
column is a 1, I would like ppReport1 to use a template called 'REPB'.
I tried the following code on the pipeline's OnTransversal event:
(Saccounts is the query that connects to the pipeline)
case Saccounts.FieldByName('REP_NAME').AsInteger of
0 : ppReport1.Template.DatabaseSettings.Name := 'REPA';
1 : ppReport1.Template.DatabaseSettings.Name := 'REPB';
end;
ppReport1.Template.LoadFromDatabase;
ppReport1.Reset;
The report does not error out or give an AV. But the template stays the
same for all records in the result set.
Any suggestions?
Thanks,
Bo Manry
bom@medmanagementllc.com
I would like to be able to load a template in ppReport1 depending on a field
value in the pipeline. For example, my result set has a column called
'REP_NAME' that has values of a 0 or 1. If the value of the column is a 0,
I would like ppReport1 to use a template called 'REPA'. If the value of the
column is a 1, I would like ppReport1 to use a template called 'REPB'.
I tried the following code on the pipeline's OnTransversal event:
(Saccounts is the query that connects to the pipeline)
case Saccounts.FieldByName('REP_NAME').AsInteger of
0 : ppReport1.Template.DatabaseSettings.Name := 'REPA';
1 : ppReport1.Template.DatabaseSettings.Name := 'REPB';
end;
ppReport1.Template.LoadFromDatabase;
ppReport1.Reset;
The report does not error out or give an AV. But the template stays the
same for all records in the result set.
Any suggestions?
Thanks,
Bo Manry
bom@medmanagementllc.com
This discussion has been closed.
Comments
template to be lost, however, since you are closing the query, I don't know
what you will get when the OnTraversal fires again. I guess you will have
to place a breakpoint in this event handler to find out if the case is
coming up with. It must be coming back with REPA everytime if that report
is the one getting loaded.
Since, you are causing the queries for the report to get closed when you
call Reset, you may just want to fire a single query before running the
report, in order to determine which report you want to load. This way you
won't cause the queries to be opened twice for the report.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
shot in the dark.
My result set looks like this:
ID NAME REP_NAME
-------------------------------------
1 BO MANRY 0
2 JOE THOMAS 0
3 HEATHER 1
4 MICHELLE 0
The ppReport1 is linked to a pipeline that is connected to the query that
contains the above result set.
When the ppReport1.Print method is called, the report will begin
transvering data through the pipeline.
On the 3rd transversal (3rd page on printout), the value in the column
REP_NAME is now a 1. I would like to use a different template for this 3rd
page of the report (REPB). On the 4th transversal (4th page on printout),
the value in the column REP_NAME is now a 0. I would like to use a REPA as
the template like pages 1 and 2.
Intially, it would have loaded REPA because record 1 has a value of 0 for
the REP_NAME column value.
I am trying to avoid having 2 print jobs sent to the print. I could always
filter first for all records with a value of 0 and load REPA and send it to
the printer. Then load REPB for all values of 1 and again send to the
printer. But, this would cause a collation problem.
Is there any way to change out the report template during a ppReport1.Print
action?
Thanks,
Bo
case where you want to print multiple reports as one. Connect the main
report to your REP_NAME pipeline. Now, the detail band will print 4 times(as
given in the example result set below). When the detail band does print, you
can check the REP_NAME value. You have two options at this point. Either
design the report with SubreportREPA and SubreportREPB in the detail band
and set their visibility based on the REP_NAME value, or you can use a
single subreport component and try to dynamically load the template REPA or
REPB. The end result is that you can call Print on the main report once and
the reports should print out in one print job.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com