Solved: Create on the fly labels with click events
Hi
In the attached code only the last label will recieve a a click event.
How to improve code so that every label will react to mouse click ?
Thanls
ly
code:for UserForm1
[VBA]Dim WithEvents lbl As MSForms.Label
Private Sub UserForm_Initialize()
For i = 1 To 3
Set lbl = UserForm1.Controls.Add("Forms.label.1")
With lbl
.Top = i * 20
.Left = 0
.BorderStyle = 1
.Caption = "Hey" & i
.Name = "lbl" & i
End With
Next
End Sub
Private Sub lbl_Click()
MsgBox ("Bye " & lbl.Caption) ' this works
End Sub
Private Sub lbl2_Click()
MsgBox "Bye" 'not working
End Sub
Private Sub lbl3_Click()
MsgBox ("Bye") 'not working
End Sub[/VBA]