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
                     Fields.Add objFld.Name '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

    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
                     .Name = 'txtDynamic" & f
                    .Left = lngLeft
                    .Top = 0
                    .Height = Detail.Height
                    .Tag = i
                    .Alignment = ddTXLeft
                    .Font.Name = "Arial"
                    .Font.Size = 10
                    .Text = 0.7
                    .DataField =  "L" & f
                  End With
                Next f

    End Sub


    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