Hi,
I am trying to add the required number of controls to my userform based on how many items are in sheet 2, this bit I have working but what I cant work out is that when the user clicks on the checkbox I would like the label caption of the the label lblUser to display the Environ username.
Can somebody tell me if this is possible?
I am trying to add the required number of controls to my userform based on how many items are in sheet 2, this bit I have working but what I cant work out is that when the user clicks on the checkbox I would like the label caption of the the label lblUser to display the Environ username.
Can somebody tell me if this is possible?
Code:
Private Sub UserForm_Initialize()
Dim Rng As Range
Dim c As Range
Dim Ctrl As Object
Dim x As Long
Dim Count As Long
Set Rng = Sheet2.Range(Sheet2.Range("C5"), Sheet2.Range("C" & Rows.Count).End(xlUp))
x = 50
Count = 1
For Each c In Rng
If Not c = Empty Then
Set Ctrl = Me.Controls.Add("Forms.Label.1", "lblItem" & Count, True)
With Ctrl
.Width = 150
.Height = 30
.FontSize = 16
.Top = x
.Left = 30
.Caption = c
End With
Set Ctrl = Me.Controls.Add("Forms.Checkbox.1", "chk" & Count, True)
With Ctrl
.Top = x
.Left = 190
End With
Set Ctrl = Me.Controls.Add("Forms.Label.1", "lblUser" & Count, True)
With Ctrl
.Width = 150
.Height = 30
.FontSize = 16
.Top = x
.Left = 210
End With
x = x + 40
Count = Count + 1
End If
Next c
End Sub