Now see how easy that is... after HOURS of googling!
Thanks Pike... You're a GENIUS!
Now see how easy that is... after HOURS of googling!
Thanks Pike... You're a GENIUS!
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:
'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
Display More
The class module LoadPoints:
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
Display More
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.
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
Display More
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