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

Load subreports at run-time

edited December 2008 in Subreports
I have looked extensively through the previous posts regarding dynamic
loading of subreports but cannot find a resolution to my problem. I'm using
Delphi 6, RB Enterprise 10.07.

I have written 3 full-page A4 reports separately and saved them as 3
individual RTM files. They are complex in design but not complex in terms of
the underlying query, which just has the one dataview.

I need a 3 reports to appear as if they were one 3-page report when the user
prints it. And so I created a new "master" report, that simply contains 3
subreport components, each separated by a pagebreak component. The
subreports are left unassigned. All components are on the Detail band.

In the master report's OnPrint event in RAP, I added:

procedure ReportBeforePrint;
SubReport1.Report.Template.FileName := 'Report1.rtm';
SubReport1.Report.Template.LoadFromFile;
{Leave the others out until I get subreport 1 loaded.
SubReport2.Report.Template.FileName := 'Report2.rtm';
SubReport2.Report.Template.LoadFromFile;
SubReport3.Report.Template.FileName := 'Report3.rtm';
SubReport3.Report.Template.LoadFromFile;}

The master report has a very basic query in it to give me the records
(employees in this case) I need from the database. It has 2 autosearch
values on it to filter the employee list.

When I go to Preview and click the "Search Data" (autosearch) button, I now
get 2 tabs on the Autosearch dialog. One for the dataview query in the
master report ("P45_online"), one for the query dataview from the loaded
subreport ("P45_Employee_Details1"). This is expected because I read in an
earlier post that loading an RTM into a subreport brings the dataviews from
the subreport into the main report.

However, when I click OK, I get this error:

Could not run program: ReportBeforePrint
TdaQueryDataView.FixUpMasterDataView: Could not find master dataview:
Query_P45_Employee_Details1.

Any ideas?

Also, is there anything else I'm missing or not doing right, or is there a
better way to try and achieve my 3 reports appearing as 1 report to the
user?

Thanks,
J.

--
Jason Sweby
Software Development Manager,
Carval Computing Limited, Plymouth, UK

Payroll - HR - T&A - Access Control

Comments

  • edited December 2008
    A follow-up, if I remove the query dataview from the master report, then the
    error message appears immediately when previewing the report.

    Jason.

  • edited December 2008
    Hi Jason,

    1. I would recommend removing the pagebreak components and simply loading
    your templates into three Section Style subreports in the detail band of
    your main report. These by definition will print on separate pages.

    2. The error you are getting indicates an error in the RAP
    Report.BeforePrint event of one of the templates you are loading. Try
    manually loading the template at design time into a subreport and see if you
    can see if the RAP compiler will give you clue as to what the problem is.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited December 2008
    Hi Nico,

    Thank you for the incredibly fast response and the perfectly accurate
    answer!

    I removed the page breaks, changed the 3 subreports to Section Style and
    instantly the whole thing just worked. The error message even went, so I now
    have it working as I'd hoped.

    Thank you very much once again for the excellent support.

    Jason.

  • edited December 2008
    Damn spoke too soon. The report displays correctly straight away because of
    the hard coded values in the AutoSearch criteria. Once I click the icon to
    change them I get the error.

    Will investigate further but I have to tell you that the 3 reports that are
    loaded into subreports don't have any RAP code at all.

    Jason.

    loading
    is.
  • edited December 2008
    Further testing done.

    1. Created a brand new application, just dropped on the database component
    and the TppReport component. Loaded the report at design time and it ran.
    Changed the autosearch parameters, ran fine.

    2. Cleared the report, dropped a subreport on to the new blank report.
    Loaded the report template at design time into the subreport. The query
    dataviews became visible in the Calc tab. Report ran perfectly.

    Jason.
  • edited December 2008
    Must have been something wrong with the master report because I started
    again and it's all fine now.

    I've long had an issue where if you go to File|New to start a new report, it
    leaves the old data pipelines behind. This I think is what caused the
    underlying issue.

    Thanks,
    Jason.
  • edited December 2008
    Sorry to keep reposting but I keep getting further.

    It worked with my new master report because I was loading the report
    templates into the subreports at design time.

    It then cleared the 3 subreports, replaced them with 3 blank new ones and
    then added the following code to the ReportBeforePrint of the master report:

    SubReport1.Report.Template.FileName := 'report1.rtm';
    SubReport2.Report.Template.FileName := 'report2.rtm';
    SubReport3.Report.Template.FileName := 'report3.rtm';

    SubReport1.Report.Template.LoadFromFile;
    SubReport2.Report.Template.LoadFromFile;
    SubReport3.Report.Template.LoadFromFile;

    This then gave me the error I originally posted about.
    Jason.

  • edited December 2008
    > I've long had an issue where if you go to File|New to start a new report,

    By design, File | New does not clear out the data.

    Perhaps in the future we could add a preference or another option to clear
    out the data.

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

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited December 2008

    You could try adding a line to clear out the data, prior to loading the
    report. Perhaps that will help

    // clear data

    myReport.FreeModules;

    // load the reports




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

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited December 2008
    Thanks for coming back. I'm doing it all within RAP and the FreeModules
    method isn't supported.

    Jason.

  • edited December 2008
    > Thanks for coming back. I'm doing it all within RAP and the FreeModules

    Ok, well you do /not/ want to call FreeModules from RAP - that will free the
    codemodule and datamodule. There is only one datamodule - it belongs to the
    main report. When a childreport loads, its dataviews are merged into the
    main repot's datamodule. I notice you are using RB 10.07., you might try
    testing with RB 10.09 and RB 11.

    Btw, you can easily extend RAP - see the following link.

    http://www.digital-metaphors.com/rbWiki/RAP/Extending_RAP/Overview

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

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.