Home Subreports

How to get the PageCount of a SubReport in the MainReport

edited May 2005 in Subreports
I want to print invoices for several customers in one report. My report
has the following structure:
MainReport.Header: There is a logo and the customer address
MainReport.Detail: There is the subreport
SubReport.Detail: The invoice positions for the customer

When a invoice for a customer has more than one page, then the customer
address should be made invisible and only the logo should be printed in
the MainReport.Header from the second page on. The only way to make the
customer address invisible, is in the BeforePrint-Event of the
Mainreport.Header. But I haven't found a way in this event to find out
whether the subreport has one or more pages. I have tried
ppChildReport1.absolutePageCount or ppChildReport1.PageCount, but I
always get 1.
Can anyone give me a hint?

Regards

Guido

Comments

  • edited May 2005
    Hi Guido,

    Make sure your report has its PassSetting property set to psTwoPass. This
    will calculated the pages needed before displaying the report and then the
    ChildReport.AbsolutePageCount should give you a correct value.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2005
    > Make sure your report has its PassSetting property set to psTwoPass. This

    I have set PassSetting to psTwoPass, but in the BeforePrint-Event I get
    always AbsolutePageCount=1.

    Regards

    Guido
  • edited May 2005
    Hi Guido,

    Sorry, I missed that you were using the BeforePrint event. Instead of using
    this event, try using the OnStartPage event or Band.BeforePrint event to
    check the AbsolutePageCount. Note that you will need to first check that
    you are on the second pass of the report or the value returned will not be
    correct.

    if Report.SecondPass then
    if Report.AbsolutePageCount > 1 then
    begin
    //Do something cool
    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2005
    > Sorry, I missed that you were using the BeforePrint event. Instead of using


    I'm not really sure, what you mean. Here's what I have done:

    procedure TForm1.MainReportStartPage(Sender: TObject);
    begin
    if MainReport.SecondPass then
    ppLabel1.Caption:=inttostr(ChildReport.AbsolutePageCount);
    end;

    ppLabel1 is in the Header of the MainReport and still get always 1 for
    the ChildReport.AbsolutePageCount.

    Regards

    Guido
  • edited May 2005
    Guido,

    Instead of using a TppLable, try using a TppVariable. Inside its OnCalc
    event set the Value property equal to the AbsolutePageCount. The following
    code worked correctly for me.

    procedure TForm1.ppVariable1Calc(Sender: TObject; var Value: Variant);
    begin
    Value := 'Total Pages (Subreport): ' +
    IntToStr(ppChildReport1.AbsolutePageCount);
    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2005
    The ppLabel is just for testing. As I mentioned in my first mail, I want
    , that when the ChildReport has more than one page, the customer address
    should be made invisible from the second oage on. Therefore I have a
    region 'customerregion' with several ppDBTextFields for customer name,
    street and so on. This region is on MainReport.Header and what I try to
    do is:

    CustomerRegion.Visible:=(ppChildReport1.AbsolutePageCount>1);

    I hope now it's clearer, what I try to do. Can you please tell me, in
    which event of MainReport I can add the above codeline?

    Regards

    Guido
  • edited May 2005
    Hi Guido,

    The following code worked correctly for me when I tested it on my machine...

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ppReport1.CachePages := True;
    ppReport1.Print;
    end;

    procedure TForm1.ppReport1StartPage(Sender: TObject);
    begin
    if (ppReport1.SecondPass) and (ppReport1.PageNo > 1) then
    ppRegion1.Visible := False;
    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2005
    Nico Cizik (Digital Metaphors) wrote:
    I think, you meant

    procedure TForm1.MainReportStartPage(Sender: TObject);
    begin
    if (MainReport.SecondPass) and (ChildReport.PageNo > 1) then
    ppRegion1.Visible := False
    else
    ppRegion1.Visible := true;
    end;

    Then ppRegion1 is always visible. The problem is always the same, it
    seems, that the MainReport isn't able to find out, how many page the
    ChildReport has.
    BTW, I'm working with RB7, can this cause the problem?

    Regards

    Guido
  • edited May 2005
    Hi Guido,

    Sorry, I completely misunderstood what your report looks like. If you are
    creating a master/detail report, try creating a group around the master
    field and use the group header rather than the page header to hold the
    address. Then be sure to have the group header only print on the first page
    of the group. Take a look at the following example...

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


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2005
    That's it, thanks for your help.

    Regards

    Guido
This discussion has been closed.