Knowledge Base

How to set up Report Builder to print a second page when processing invoices

Hint Ref: 021212100014
Hint Date: 10/12/2012

Hint Details:

ISSUE

 

A customer wanted to print a second page letter, after each invoice, when printing batch invoices - but only if certain criteria where met for that invoice.

SOLUTION

In order to print the second page a SubReport must be used, but special conditions must be set up in order for it to work correctly.

1. A SubReport cannot be placed in a report Footer, so it must be placed in the Group Footer instead.

2. If the Second page is to display data from the database, it MUST use a separate report SQL Pipeline (with the main pipeline set up and the Master Pipeline), even if the data to be displayed is available directly from the main pipeline. This because the pipeline the subreport uses must only have a single record in the record set it is trying to display ( one for each record in the master pipeline and the master pipeline itself will have many!).

So, if you wanted to display the Contract Number and Unit List from the main pipeline in the SubReport, and they were set up in the main pipeline as ContNo and UnitList, you would need something like the following in the Sub-Pipeline:

select
string( (:ContNo)) as ContrNo, 
string((:UnitList)) as Units

3. Setup the condition in the main pipeline which will determine if the SubReport is printed or not. For example:

IqacDocument.DocumentID as iDocID,
If exists (select subcontractid from subcontract join accountlink where newratedate is not null and accountlink.documentid=iDocID) then 1 else 0 endif as NeedLetter,

4. Then create a new event on the 'Calc' tab of the Main Report under

Report / Groups / Footer / SubReport1 / OnPrint (right click on 'OnPrint' and select 'New')

That might look something like this:

begin
      SubReport1.Visible:= False;
      if main['NeedLetter']=1 then
        SubReport1.Visible:= True;
end;

5. On the 'Design' tab of the main report, rigth click on the SubReport and change it from 'Child' to 'Section' (this will ensure that the SubReport letter has it's own page.)

6. Populate the SubReport's Header, Detail and Footer sections as required.

No other settings changes should be required.