Home Subreports
New Blog Posts: Merging Reports - Part 1 and Part 2

Dynamically load Multiple SubReports on Group Change

edited September 2008 in Subreports
Hi,

I'm using Delphi 5 and RB 7.04b

I have 5 different SubReports that I have created and saved to files
which are basically just lines and text (like 'page styles') with no
data fields - for one column of a 2 column report in landscape
orientation. One SubReport is located in the Detail Band. Each SubReport
has been tested separately in the designer so only 2 records are printed
per page. That works fine when there is only one group.

Now I'm trying to dynamically load a different SubReport whenever a
'group value' changes. Group A uses SubReport1, Group B uses SubReport
2, Group C use SubReport 3, etc. I have the group value in the Group
Header Band but not 'visible' since it also is in the Detail Band. I
have tried having the Group break to a new page or a new column - both
works the same.

The report works fine for the first 2 group changes (the initial load
and then the next change) and then I only get the column footer to show
for the rest of the pages.

What am I doing wrong?

Here's my coding:

procedure TScribeSheetForm1.PrintButton1Click(Sender: TObject);
begin
oldgroup := scribe2.GetCField('groupname');
{set the initial report template name}
ppReport1.Template.FileName := dbfpath + 'ScribeOneGrphd.rtm';
ppSubReport1.Visible := true;
with ppChildReport1 do begin
Template.FileName := GetSubReportName(oldgroup);
Template.LoadFromFile;
end;
ppReport1.Print;
end;

procedure TScribeSheetForm1.ppGroupHeaderBand1BeforePrint(Sender: TObject);
var cname, filename : string;
begin
cname := scribe2.GetCField('groupname');
if cname <> oldgroup then begin
filename := GetSubReportName(cname);
with ppChildReport1 do begin
Template.FileName := filename;
Template.LoadFromFile;
end;
oldgroup := cname;
end;
end;

Thanks,
Marie

Comments

  • edited September 2008

    Try putting all 5 subreports in the detailband and then use the
    DetailBand.BeforePrint event to toggle the subreport visibility.

    Avoid loading subreports while the report is executing - the report engine
    initializes all the subreports at the beginning - when report.Print is
    called.



    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited September 2008
    Thanks Nard! I wasn't aware that all the subreports needed to be
    initialized before Report.Print.

    Marie
This discussion has been closed.