Dynamically create summary fields

Posted by: blackriver on 4 August 2017, 3:18 pm EST

  • Posted 4 August 2017, 3:18 pm EST

    I can dynamically create Labels(in PageHeader section) and Fields(in Details Section).I can also dynamically populate fields with values from database.I can also check if a certain fields contains a numeric value and set the OutputFormat accordingly.

    But now I would like to know how to add a certain number of summary fields to PageFooter section depending on how many numeric fields there are in Details section.

    For example;

    If I have Price and Value in Details,I’d like to have 2 summary fields in PageFooter(PriceTotal,ValueTotal).



    Where to I start?





  • Posted 4 August 2017, 3:18 pm EST

    And after a cup of coffee and some rest I managed to solve my problem.It was quite simple.Just added a GroupHeader and Footer insted of PageHeader and Footer.Works like a charm!

    If anyone wants to see the code I used,be sure to post here.Maybe you can improve my work.



    Bye for now!



  • Posted 4 August 2017, 3:18 pm EST

    this is just great:) could you please tell me how i can dynamically add columns in a table depending on how many parameters the user enters. thanks

  • Posted 4 August 2017, 3:18 pm EST

    If you want to add X number of fields at run-time to your report, you should use something like this:



    Dim rptMain as ActiveReport1

    Dim oCtrl as Object



         Set rptMain = New ActiveReport1

         'Set the datasource for your report

         Set oCtrl = rptMain.Sections(“Detail”).Controls.Add(“DDActiveReports2.DataControl”)



         oCtrl.ConnectionString = YourConnectionString

         oCtrl.Recordset = YourRecordSet



    'Set up Sections for your report

    'set up group header

        rptMain.Sections.Add “Group”, 1, ddSTGroupHeader, 400

        rptMain.Sections.Add “foot”, 3, ddSTGroupFooter, 500

       

        rptMain.Sections(“Group”).Visible = True

        rptMain.Sections(“Group”).GrpKeepTogether = True

        rptMain.Sections(“Group”).KeepTogether = True

        rptMain.Sections(“Group”).BackStyle = 0

        rptMain.Sections(“Group”).Repeat = 1

        rptMain.Sections(“Group”).CanGrow = True

       

    'set up group footer

       

        rptMain.Sections(“foot”).Visible = True

        rptMain.Sections(“foot”).BackStyle = 0

        rptMain.Sections(“foot”).KeepTogether = True

        rptMain.Sections(“foot”).CanGrow = True

       

        'setting up the detail section



        rptMain.Detail.Height = 300

        rptMain.Detail.BackStyle = 0 '1 = normal 0 = transparent

        rptMain.Detail.BackColor = &HC0C0C0

        rptMain.Detail.ColumnCount = 1

        rptMain.Detail.KeepTogether = True

        rptMain.Detail.CanGrow = True

        rptMain.Detail.Visible = True



    Now that you have everything set up, you can add Labels,Fields,Lines and everything else to your report. I’m not familiar with your exact requirements, but if you are working with records from RecordSet, then you should keep in mind that every Field control needs to have its DataField set to corresponding FieldName from the recordSet.



    If you have more question, I would be glad to help!

  • Posted 4 August 2017, 3:18 pm EST

    thankyou so much for all your help

  • Posted 4 August 2017, 3:18 pm EST

    will this only work in ActiveReports? or will it work in dataDynamics reports too?

  • Posted 22 December 2021, 6:23 am EST

    Hello blackriver,

    Not sure if you can help me, because your post was added 4 years ago, but who knows maybe I succeed to get your help. Could you please show me how did you resolve this? I’m having the same issue, and I tried the thing you said but it didn’t resolve it, maybe I did it wrong. When I put the summary fields in the group footer the values don’t show up, could be something I need to change in the properties? Please tell me what I can do.

    Thanks in advance!

  • Posted 4 January 2022, 2:11 pm EST

    Hello abdelouhabe,

    Apologies for the delay. I have shared a sample application demonstrating how you can add summary fields to the report dynamically in ActiveReports for your reference.

    Hope it helps.

    Regards

  • Posted 4 January 2022, 2:13 pm EST

    Seems the sample didn’t get attached earlier.Dynamic Summary Report VB.zip

Need extra support?

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

Learn More

Forum Channels