PetLahev
New Member
- Joined
- Jul 30, 2009
- Messages
- 28
Hello
I've been trying to solve this problem for hours with no success.
Please, kick me
It should be simple
1, form with labels that are added dynamicaly
2, a common class that catch labels event
I prepared a sample with one form and one class
code in the form - UserForm1
code in the class - LablesClass
I'd like to achieve a result when every click on any label will raise the RaiseEvent code.
Thanks
Pat
I've been trying to solve this problem for hours with no success.
Please, kick me
It should be simple
1, form with labels that are added dynamicaly
2, a common class that catch labels event
I prepared a sample with one form and one class
code in the form - UserForm1
Code:
Dim storeInstances As Collection
Dim WithEvents lblEvents As LablesClass
Private Sub lblEvents_Clicked(labelName As String)
MsgBox "Whooo the raise event works for " & labelName
End Sub
Private Sub UserForm_Initialize()
Set storeInstances = New Collection
Set lblEvents = New LablesClass
Set lblEvents.lablesEvent = Label1
storeInstances.Add lblEvents
Set lblEvents = New LablesClass
Set lblEvents.lablesEvent = Label2
storeInstances.Add lblEvents
Set lblEvents = New LablesClass
Set lblEvents.lablesEvent = Label3
storeInstances.Add lblEvents
End Sub
Code:
Public WithEvents lablesEvent As MSForms.Label
Public Event Clicked(labelName As String)
Private Sub lablesEvent_Click()
MsgBox lablesEvent.Name
RaiseEvent Clicked(lablesEvent.Name)
End Sub
Thanks
Pat