Announcement

Collapse
No announcement yet.

Get attributes from class module

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get attributes from class module



    Hi

    I created a number of textboxes during runtime, and added them to a collection and class module. If I click on the textbox, I can then trigger the mousedown event in the class module which first checks which of the option buttons on the same userform is selected, and based on that, change the text in the textbox to the value of the attribute that corresponds to the option button. I want to add a button to the userform that will loop through all the controls on the userform, and change the text of the textboxes to the selected option button.

    Creating the textboxes:

    Code:
    'First in a module :
    Public LoadPointArray() As New LoadPoints
    
    'Then in a procedure in the same module as above (looping through a recordset from SQL):
    
    Set txt = frmMeeting.Controls("frm" & rs!Level_ID & rs!Tunnel_ID).Controls.Add("Forms.textbox.1", "txt" & rs!Level_ID & rs!Tunnel_ID & rs!Ring_ID, True)
        With txt
          .Text = rs!Level_ID & rs!Tunnel_ID & rs!Ring_ID
          .Left = 0
          .Width = 70
          .Top = txt.Height * CDbl(rs!Row)
          .Enabled = True
        End With
        TotalTXT = TotalTXT + 1
    
        'Add to Rings collection for Class Module
        ReDim Preserve LoadPointArray(1 To TotalTXT)
        Set LoadPointArray(TotalTXT).txtLoadPoints = txt
          LoadPointArray(TotalTXT).LoadPoint = txt.Text
          LoadPointArray(TotalTXT).Target = rs!Target
          LoadPointArray(TotalTXT).Actuals = rs!Actuals
          LoadPointArray(TotalTXT).Remain = rs!Target - rs!Actuals
          LoadPointArray(TotalTXT).Compliance = Compliance
          LoadPointArray(TotalTXT).Status = rs!Reason
          LoadPointArray(TotalTXT).TonsPerDay = DailyTons
    The class module LoadPoints:
    Code:
    Public WithEvents txtLoadPoints As MSForms.TextBox
    Public txtLoadPoint, LoadPoint, Status As String
    Public Target, Actuals, Remain, TonsPerDay As Integer
    Public Compliance As Double
    
    Public Sub txtLoadPoints_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
    If frmMeeting.optStatus.Value = True Then
      frmMeeting.Controls("txt" & LoadPoint).Text = Status
    End If
    If frmMeeting.optTarget.Value = True Then
      frmMeeting.Controls("txt" & LoadPoint).Text = Target
    End If
    I'm sure it should be easy? Thanks in advance.


    Reading now it could still be unclear... And I can likely NOT have a button, but rather when the option button is clicked, all textbox values must change to the selected option button value.

    Code:
    Private Sub optTarget_Click()
    Dim cntControl As Control
    Dim lCounter As Long
    For lCounter = 0 To frmMeeting.mpgAreas.Pages.Count - 1
      For Each cntControl In frmMeeting.mpgAreas.Pages(lCounter).Controls
        If Left(cntControl.Name, 3) = "txt" Then
         'RaiseEvent MouseDown(Right(cntControl.Name, Len(cntControl.Name) - 3))
          MsgBox cntControl.Name
          'cntControl.Text = cntControl.Name
        End If
      Next cntControl
    Next lCounter
    End Sub
    for optTarget, the values should change to the corresponding
    LoadPointArray(TotalTXT).Target for optActuals, all the textboxes should change to
    LoadPointArray(TotalTXT).Actuals etc, etc
    Last edited by pike; 5 days ago. Reason: reset replies to zero

  • #2
    Hello,
    doesnt this work?
    Code:
    For lCounter = 0 To frmMeeting.mpgAreas.Pages.Count - 1
      For Each cntControl In frmMeeting.mpgAreas.Pages(lCounter).Controls
        If Left(cntControl.Name, 3) = "txt" Then
           cntControl.Text = cntControl.Name
        End If
      Next cntControl
    Next lCounter
    If the solution helped please donate to RSPCA

    Sites worth visiting: Rabbitohs | Excel-it royUK | Excel Matters Rory | Kris' Spreadsheet Solutions | Domenic xl-central | The Smallman

    Comment


    • #3
      You can just loop the array values
      Code:
      Private Sub optTarget_Click()
          Dim cntControl As Long
          For cntControl = 1 To UBound(LoadPointArray)
              LoadPointArray(cntControl).txtLoadPoints.Text = LoadPointArray(cntControl).Actuals
          Next cntControl
      End Sub
      Last edited by pike; 1 day ago.
      If the solution helped please donate to RSPCA

      Sites worth visiting: Rabbitohs | Excel-it royUK | Excel Matters Rory | Kris' Spreadsheet Solutions | Domenic xl-central | The Smallman

      Comment


      • #4
        for the event to work should possibly be ....
        Code:
        Public WithEvents txtLoadPoints As MSForms.TextBox
        Public txtLoadPoint as string, LoadPoint as string, Status As String
        Public Target as long, Actuals as long, Remain as long, TonsPerDay As long
        Public Compliance As Double
        
        Public Sub txtLoadPoints_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
        If frmMeeting.optStatus.Value = True Then
          txtLoadPoints.Text = Status
        end if
        if frmMeeting.optTarget.Value = True Then
          txtLoadPoints.Text = Target
        End If
        Last edited by pike; 4 days ago.
        If the solution helped please donate to RSPCA

        Sites worth visiting: Rabbitohs | Excel-it royUK | Excel Matters Rory | Kris' Spreadsheet Solutions | Domenic xl-central | The Smallman

        Comment


        • #5
          Now see how easy that is... after HOURS of googling!

          Thanks Pike... You're a GENIUS!

          Comment


          • #6


            A very stable genius?? Just glad to help and thank you for posting an interesting question
            If the solution helped please donate to RSPCA

            Sites worth visiting: Rabbitohs | Excel-it royUK | Excel Matters Rory | Kris' Spreadsheet Solutions | Domenic xl-central | The Smallman

            Comment

            Working...
            X