How do I dynamically place new fields on a new page

Posted by: planza on 4 August 2017, 2:51 pm EST

  • Posted 4 August 2017, 2:51 pm EST

    I am working on a report that I generate entirely from the class file that calls the report object. I have it dynamically adding fields to the report at run-time according to how much data I have etc. The problem that I am running into is that I can't figure out how to get the report to page properly. I have some code to create a new page, but I cannot figure out how to dynamically position the fields to where they appear on the new page.


    This is the code that I have to create the new pages in the class:


     'new page every 6 cols
       If x Mod 6 = 0 And x <> 0 Then
        'new page
        GradeSummaryReport.Detail.NewPage = ddNPAfter
       Else
        'no new page
        GradeSummaryReport.Detail.NewPage = ddNPNone
       End If


    This is the code that I use to create the fields. This code block is above the pagination code.


     


    'create detail rows for the asg column created below
          Set ghCtrl = GradeSummaryReport.Sections("Detail").Controls.Add("DDActiveReports2.Field")
          With ghCtrl
            .Name = "txtDynAsgPoints" & x & y
            .Height = 270
            .Width = 1800
            .Top = y * 270
            .Left = colPosition
            .BackStyle = 0 '1 = normal, 0 = transparent
            .ForeColor = &H0
            '.Text = "TEST" & x
            If Trim(strDynDetailValue) = "" Then
              strDynDetailValue = "NO DATA"
            End If
            .Text = strDynDetailValue
           End With


     


    Any help will be appreciated.


    Thanks,


    P


     

  • Replied 4 August 2017, 2:51 pm EST

    As a design rule you don't want to place controls onto the report after the report start event.  You will want to add sections to the report as needed and add controls
    to those sections before the report is run.  While it is running you
    can manipulate the properties, but avoid removing/adding controls.  The rendering of controls will repeat as needed by the ActiveReports engine.  The detail will repeat for each record, groups headers/footers by their grouped data.
    ActiveReports will generate the report in line with reading from the data source and will fire a detail section for every record.  If your report is unbound you will need to keep track of the EOF parameter manually.
     
  • Replied 4 August 2017, 2:51 pm EST

    Thanks, but that isn't what I need to know. I cannot rely upon the detail section repeating for this report for various reasons. What I need to know is how I can force the report to create a new page and paint new controls onto that new page before the report runs.


    Something liek this:


    If numberofColumns >6 Then


    makeNewPage


    colposition = at start of new page


    End If


    I can create the number of pages that I will need before beginning to append controls if need be. Then I could maybe loop through the pages collection or something. Would this work? If so, then can you post some reference code on how to do this? If not, then what method can I use to place new controls onto page n from the class file before detail format and all of that?


    Maybe something like report.pages(n).sections("detail").controls.add("DDActiveReports2.Field") where n is the page number?


     


    Thanks,


    P

  • Replied 4 August 2017, 2:51 pm EST

    You will want to look into the ActiveReports.Document.Pages Namespace for methods and properties pertaining to drawing on the page.  This will allow you to draw on a blank page added to the pages collection or a page that has been generated by ActiveReports.  Any changes to a page must be done AFTER the report runs or they will be over written by the report engine as it renders the report.

    You can hide, move, change certain properties of controls as the report runs.  However there is no way to add a control after the report starts running.  You can use subreports however and generate the controls that will be on that subreport before you asign the report object to the subreport control.
  • Replied 4 August 2017, 2:51 pm EST

    Thanks, I will give it a shot
  • Replied 4 August 2017, 2:51 pm EST

    I think that is the second time i have done that, given .NET advice on the VB 6 forums.

    You will want to take a look at the report.Canvas and its properties.  In the documentation it would be with .DrawText, .DrawElipse, and the like.  The namespace I mentioned was the ActiveReports for .NET 1.0 product, sorry for any confusion.
Need extra support?

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

Learn More

Forum Channels