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

Repeating Subreports within a report

edited April 2007 in Subreports
I want to generate a report which has at least 5 pages and may have as
many as 14 pages. (I really do not know the upper limit but I believe
the report will always be below 14. The pages in the report are:

First page
Second page
Third through m pages
where: n is the number of variable pages (1<=n<=10)
m = n + 2
Page m + 1
Page m + 2

I will always know "n" before the report is generated and printed.

The "n" reports are identical except for their data values. That is
they have the same labels and data value fields but the actual data
value will change for each of the "n" pages.

I currently have my first page on the main report builder form

The second page is a subreport in the main report's Summary field

Subsequent pages are subreports in the predecessor's subreport Summary field

Any idea how I should handle the unknown number of subreport's embedded
within the report.

Comments

  • edited April 2007
    Hi Gary,

    At what point do you know how many subreports (pages) you are going to need
    to tack on the end of the report? If this is based on some data in a
    dataset, you could possibly dynamically create each subreport for each
    record as the report generates in code. Take a look at the following
    article on creating subreports in code.

    -------------------------------------------------
    TECH TIP: Creating a SubReport in Code
    -------------------------------------------------

    A subreport is comprised of two objects:

    1. SubReport control
    The subreport control is added to a band of the
    'parent' report. It has properties such as
    ShiftRelativeTo, PrintBehavior, etc.
    In the Report Designer, the subreport is drawn
    as a rectangle.


    2. ChildReport
    The child report is a descendant of CustomReport and has
    most of the same properties as a standard Report.
    The child report has a separate layout workspace in the report
    designer that is accessible by selecting the tabs at the bottom
    of the designer.




    When dynamically creating a subreport in code you need to create the
    subreport and the underlying child report. The subreport.Report property can
    then be used to access the child report.

    This is demonstrated in the following example:




    var
    lSubReport: TppSubReport;
    lReport: TppChildReport;
    lLabel: TppLabel;
    lDBText: TppDBText;


    begin

    lSubReport := TppSubReport.Create(Self);

    {add to the main report's detail band}
    lSubReport.Band := ppReport1.DetailBand;

    {create the child report (parameters: main report) }
    lSubReport.CreateReport(ppReport1);

    lReport := TppChildReport(lSubReport.Report);

    {assign a datapipeline}
    lReport.DataPipeline := plCustomers;

    {create the default set of bands}
    lReport.CreateDefaultBands;

    lLabel := TppLabel.Create(Self);
    lLabel.Band := lReport.TitleBand;
    lLabel.Caption := 'Customers';

    lLabel.Font.Name := 'Times New Roman';
    lLabel.Font.Size := 24;

    lDBText := TppDBText.Create(Self);
    lDBText.Band := lReport.DetailBand;
    lDBText.DataPipeline := plCustomers;
    lDBText.DataField := 'CustNo';

    lDBText.Color := clYellow;
    lDBText.Font.Name := 'Times New Roman';
    lDBText.Font.Size := 12;


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2007
    The number of repeating sub reports is based on the number of data base
    records. each record has 2 parallel child records. Their are
    calculations required with the data in these three tables. The
    calculations are not straight forward so I will have to use a
    combination of DBfields, DBJITs, and DBGraphics.

    I was hoping I could create one "template" in a loop. For example,
    after a page has finished printing, a decision could be made on whether
    the last repeating page was complete and I could move on to the last two
    pages in the report or that their were more "repeating pages" to print.
    If so I could move to the next master record and simply fill in the
    fields again.

  • edited April 2007
    Hey

    I used the example in a simple test app, except I got the data from a
    jit pipeline. It worked in that it produced output but was not what I
    wanted. I want the sub report to be the next page of the report. I
    used the following code:

    PROCEDURE tfrmMain.IndividualSubRpt;
    VAR
    lSubReport: TppSubReport;
    lChildReport: TppChildReport;
    lLabel: TppLabel;
    lDBText: TppDBText;
    BEGIN

    lSubReport := TppSubReport.Create(Self);

    {add to the main report's detail band}
    lSubReport.Band := Rpt.SummaryBand;
    lSubReport.PrintBehavior := pbSection;

    {create the child report (parameters: main report) }
    lSubReport.CreateReport(Rpt);

    lChildReport := TppChildReport(lSubReport.Report);

    {assign a datapipeline}
    lChildReport.DataPipeline := jit;

    {create the default set of bands}
    lChildReport.CreateDefaultBands;

    lLabel := TppLabel.Create(Self);
    lLabel.Band := lChildReport.TitleBand;
    lLabel.Caption := 'Name';

    lLabel.Font.Name := 'Times New Roman';
    lLabel.Font.Size := 9;

    lDBText := TppDBText.Create(Self);
    lDBText.Band := lChildReport.DetailBand;
    lDBText.DataPipeline := jit;
    lDBText.DataField := 'Name';

    lDBText.Color := clYellow;
    lDBText.Font.Name := 'Times New Roman';
    lDBText.Font.Size := 9;
    END;

  • edited April 2007
    Hi Gary,

    I'm a bit unclear about what is happening. At what point are the subreport
    created with the code below printing? You can try setting the
    ShiftRelativeTo property to the previous subreport in order to determine
    which order they are printed.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2007
    perhaps you could direct me to an example program where one or more sub
    reports are created through code. My last attempt included the first
    page with a summary band created via the Reportbuilder editor. The
    first page had one label in the header.

    The main form has a button which when clicked does the following:

    subrpt;
    ppReport1.print;

    where:

    PROCEDURE TfrmMain.SubRpt;
    VAR
    lSubReport: TppSubReport;
    lReport: TppChildReport;
    lLabel: TppLabel;
    lDBText: TppDBText;
    BEGIN
    lSubReport := TppSubReport.Create(Self);
    {add to the main report's detail band}
    // lSubReport.Band := rpt.DetailBand;
    lSubReport.Band := ppReport1.SummaryBand;
    {create the child report (parameters: main report) }
    lSubReport.CreateReport(ppReport1);
    lSubReport.PrintBehavior := pbSection;
    lReport := TppChildReport(lSubReport.Report);
    {assign a datapipeline}
    lReport.DataPipeline := jit;
    {create the default set of bands}
    lReport.CreateDefaultBands;
    lLabel := TppLabel.Create(Self);
    lLabel.Band := lReport.TitleBand;
    lLabel.Caption := 'Name';
    lLabel.Font.Name := 'Times New Roman';
    lLabel.Font.Size := 24;
    lDBText := TppDBText.Create(Self);
    lDBText.Band := lReport.DetailBand;
    lDBText.DataPipeline := jit;
    lDBText.DataField := 'Name';
    lDBText.Color := clYellow;
    lDBText.Font.Name := 'Times New Roman';
    lDBText.Font.Size := 12;
    END;



  • edited April 2007
    Hi Gary,

    Below is a quick example of what I am talking about. This should get you on
    the right track.

    http://www.digital-metaphors.com/tips/CreateSectionSubreportsInCode.zip

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.