Hello Logit,
The syntax below is universal with the userform name also captured.
Class Code Named clsFrmCtls
Option Explicit
Public mName
Public nlabel
Public mFrm As Object
Public Event SelectedChange(objCtr, intCtr)
Public WithEvents mTextBox As MSForms.TextBox
Private Sub mTextBox_Change()
nlabel = Replace(mName, "TextBox", "")
RaiseEvent mFrm.SelectedChange(mName, nlabel)
End Sub
Userform Code
Option Explicit
Dim mcolEvents As Collection
Public Sub SelectedChange(objCtr, intCtr)
Me.Controls("Label" & intCtr).Caption = Me.Controls(objCtr).Text
End Sub
Private Sub UserForm_Initialize()
Dim cCBEvents As clsFrmCtls
Dim ctrl As MSForms.Control
Set mcolEvents = New Collection
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
Set cCBEvents = New clsFrmCtls
Set cCBEvents.mFrm = Me
cCBEvents.mName = Me.Controls(ctrl.Name).Name
Set cCBEvents.mTextBox = Me.Controls(ctrl.Name)
mcolEvents.Add cCBEvents
End If
Next ctrl
End Sub
Private Sub butClose_Click()
Unload Me
End Sub
Private Sub UserForm_Terminate()
Set mcolEvents = Nothing
End Sub