Combine multiple reports into one

Posted by: djanim8 on 4 August 2017, 2:32 pm EST

  • Posted 4 August 2017, 2:32 pm EST

    Is there any way to combine X number of reports into one report to be saved/printed?
  • Replied 4 August 2017, 2:32 pm EST

    Yes you can use a reports Pages.Insert method.  Here is an example where I have a main container report, rptFinal, a static backer, rptBacker, and the actual data driven report, rptReport.  I run all three then loop through the pages collection of the data driven report, instert it's pages and static backer pages so I can print front (data) and back (static), two copies of each in a white/pink scenario.  You should be able to take the basic idea and modify it to fit your needs.

    rptReport.Run False
    rptBacker.Run False
    'rptFinal.Run False  'removed as this creates a blank page at the end, Edit on 3/13/2006
    'load backwards so it is correct when finished
    For intP = (rptReport.Pages.Count - 1) To 0 Step -1
      rptFinal.Pages.Insert 0, rptReport.Pages.Item(intP)
      rptFinal.Pages.Insert 0, rptBacker.Pages.Item(0)
      rptFinal.Pages.Insert 0, rptReport.Pages.Item(intP)
      rptFinal.Pages.Insert 0, rptBacker.Pages.Item(0)
    Next intP
    rptFinal.Printer.FromPage = 1
    rptFinal.Printer.ToPage = (rptFinal.Pages.Count - 1)
    rptFinal.PrintReport False
  • Replied 4 August 2017, 2:32 pm EST

    Thanks for this code, it's helping me for the most part.

    But I'm having a problem in that the reports are getting inserted in reverse order. One of the tasks when generating a multiple-report report is to loop through a table of orders. The order reports are getting inserted in reverse order.

    So if I run things in this order:

    Generate Customer Contact report
    Query to select Order History records, loop through records
    Insert Order History report for 2005
    Insert Order History report for 2002
    Insert Order History report for 1999
    Export as one single report

    I get the following, coming out in reverse order:

    Order History report for 1999
    Order History report for 2002
    Order History report for 2005
    Customer Contact report

    I know this is because we are using "Insert"... is there another way of doing this so it's an "Append" instead?

    EDIT: OK, nevermind, I got it to work the way I wanted to. I created a blank page report first (like in the poster's example). Executed a query to select the Order History recordset in reverse descending order, ran and inserted the Order History reports into the blank page report, then ran the Customer Contact report and inserted it. This left me with all the reports in correct order but with a blank page at the end. My final command then was to call the method objARBlank.Pages.Remove (objARBlank.Pages.Count - 1)

    Wow, if there is an easier way (HINT: There needs to be a Pages.APPEND method!), please let me know. This works, but it reminds me frighteningly of writing bubble sorting code in high-school Pascal class.


  • Replied 4 August 2017, 2:32 pm EST

    If you don't run the Final / blank report you can avoid the empty page scenario.

    The following should function the same as an APPEND method. If I was just interested in combining reports together for exporting or viewing I would use the following, which also negates the need for a blank container object. If like I was originally doing with my previous post in this thread of creating a duplicate report for carbonless printing with a static backer I would use that previous code.

    For intP = 0 To rptFrom.Pages.Count - 1
       rptInto.Pages.Insert rptInto.Pages.Count, rptFrom.Pages(intP)
    Next intP

  • Replied 4 August 2017, 2:32 pm EST

    And (this may not be of interest) you can manually create a TOC for this combined report if required. I gave brief details in a recent comment to another posting but will be happy to explain more if asked. (I am using AR1 with VB6)
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels