Adding controls from runtime

Posted by: hephie on 4 August 2017, 2:53 pm EST

  • Posted 4 August 2017, 2:53 pm EST


    It's my first day on the forum, so first of all, hy to everyone (who reads this). I've been searchin on the internet and on other forums but i couldn't find an answer on my questions. I hope you guys have one for me.

    I didn't really know where to post my question so sorry if i'm posting it in the wrong section.

    My Question:
    I'm using VB6 and Active Reports 2.0. Now what i'm trying to do (what i want to do!) is add some object from runtime,
    for example, adding a label or a textfield to my (active reports) form.

    Now in a usual VB6-Form u can do this:
                me.controls.add("vb.label", "myLabel")                 [for adding a label on to the form]
    OR       me.controls.Add"vb.textbox", "myTextbox")        [for adding a textbox on to the form]

    Well this ain't working in active reports, i hope there's another way to do this, cause there ain't another solution for my problem, i really have to add does "objects" dynamically, although, add them from runtime.

    Hope someone can help me!

  • Replied 4 August 2017, 2:53 pm EST

    Oh it is possible, very much so, I currently have several dynamic reports in daily use and there will only be more as time goes on. Take a look at this two links into the Help Files for detailed information.

    Also assuming a default installation there should be a sample project that demonstrates dynamic controls... C:\Program Files\Data Dynamics\ActiveReports 2\Samples\Visual Basic Samples\Print Bound DBGrid

  • Replied 4 August 2017, 2:53 pm EST

    Thanks, that's exactly what i was lookin for!

    but only one problem now, what i'm still trying to fix. When i use that code, to add a label.
    the program keeps going and going. I think somewhere it comes in an unendless loop. Can't find what it is.

    When i remove the new code out of the "activereport_fetchdata"-section, the "unendless loop" is gone. So it must be something with the new code (for adding objects dynamically).

    Here's my code:

    Private Sub ActiveReport_FetchData(eof As Boolean)
        If iRow > UBound(arrTreeviewItem) Then
            eof = True
            Exit Sub
        End If
    <font color="#ff0000">    Dim obj As Object
        Set obj = Hoofdrapport.Sections("Detail").Controls.Add("DDActiveReports2.Label")
        obj.Name = "lbl" & iRow
        obj.ForeColor = vbRed
        obj.Caption = arrTreeviewItem(iRow).Node_full_path
        obj.Visible = True</font>
        Fields("Eig Naam") = ""
        Fields("Eig Waarde") = ""
        Fields("Eig Eenheid") = ""
        Fields("Node_Key") = arrTreeviewItem(iRow).Node_key
        Fields("Type Object") = arrTreeviewItem(iRow).Type
        Fields("Naam") = arrTreeviewItem(iRow).Naam
        Fields("ODC") = arrTreeviewItem(iRow).ODC
        Image1.Picture = LoadPicture(arrTreeviewItem(iRow).Image)
        Fields("Node_full_path") = arrTreeviewItem(iRow).Node_full_path
        For i = 1 To UBound(arrEigenschap)
            If arrEigenschap(i).Node_key = arrTreeviewItem(iRow).Node_key Then
                Fields("Eig Naam") = Fields("Eig Naam") & vbCrLf & arrEigenschap(i).Naam
                Fields("Eig Waarde") = Fields("Eig Waarde") & vbCrLf & arrEigenschap(i).Waarde
                Fields("Eig Eenheid") = Fields("Eig Eenheid") & vbCrLf & arrEigenschap(i).Eenheid
                Exit For
            End If
        eof = False
        iRow = iRow + 1
    End Sub

    when i remove the "red highlighted" code, (or put it in comment), everything works fine. When i uncomment it, my program comes in that unendless loop.

    Anyone an idea why??


  • Replied 4 August 2017, 2:53 pm EST

    The second link states..."It is important to remember controls and sections should not be added after the ReportStart event has finished." I also believe the DD team recommends that you do NOT access sections and controls from the FetchData event, instead use the Fields collection, recordset and variables.
  • Replied 4 August 2017, 2:53 pm EST


    i'll try to put that part of the code somewhere else!

    thanks dude for the fast help!


Need extra support?

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

Learn More

Forum Channels