add a control in the detail

Posted by: esoto on 4 August 2017, 2:38 pm EST

  • Posted 4 August 2017, 2:38 pm EST

    When I try to add a control in the detail send me that message of error.  Some idea so that of this error
    This is my code.


    Private Sub CrearDetalle()
                For f = 1 To 3
                    Set objFld = Detail.Controls.Add("DDActiveReports2.Field")
                    With objFld
                    .Left = lngLeft
                    .Top = 0
                    .Height = Detail.Height
                    .Tag = i
                    .Alignment = ddTXLeft
                    .Font.Name = "Arial"
                    .Font.Size = 10
                    .Text = 0.7
                     <font color="#DEB887"> Fields.Add objFld.Name</font> 'Line Error
                    .DataField = i
                    End With
                Next f
    End Sub

    The error send is:
    Fields collection is readonly. To Add/remove fields use the DataInitialize event.



    Thank you.
    Gracias a todos
    Don Quijote de Nicaragua.
    2005/06/Error.gif
  • Replied 4 August 2017, 2:38 pm EST

    The Fields collection is databound and can only be added to in the DataInitialize event. Field controls, i.e. rename textboxes, are controls that can be added dynamically and then bound to the Fields collection. So you would want something along the following...
    http://www.datadynamics.com/ShowPost.aspx?PostID=306

    <font face="Courier New"> Private Sub ActiveReport_DataInitialize()
        Fields.Add "L1"
        Fields.Add "L2"
        Fields.Add "L3"
    End Sub

    Private Sub CrearDetalle()
                For f = 1 To 3
                  Set objFld = Detail.Controls.Add("DDActiveReports2.Field")
                  With objFld
                     <font color="#ff0000"> .Name = 'txtDynamic" & f</font>
                    .Left = lngLeft
                    .Top = 0
                    <font color="#008000"> .Height = Detail.Height
    </font>                .Tag = i
                    .Alignment = ddTXLeft
                    .Font.Name = "Arial"
                    .Font.Size = 10
                    <font face="Courier New"> <font color="#008000"> .Text = 0.7
    </font>                .DataField =  <font color="#ff0000"> "L" & f</font>
                  End With
                Next f</font></font> <font face="Courier New">
    End Sub</font>

    Why are you setting both the DataField and Text properties?

    I believe the Detail Height is not set until the BeforePrint event if you have either Cangrow or Canshrink set to true, so setting your controls equal to it in another event could have undesired results.
    http://www.datadynamics.com/ShowPost.aspx?PostID=93
Need extra support?

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

Learn More

Forum Channels