Hi Emily, You are on the right track with this. I think the problem has to do with the state of the Userform. Remember the userform has to be active in order to access the controls and values on it. You show it using the
UserForm.Show method. you can use
Me.Hide in the userform code module to Hide the userform and still have access to the controls and values on the form. To close the userform, use
Unload Me (in the userform class module) or
Unload userformname, in a procedure or userform class module.
Code:
' First Show the user Form
Sub ShowUserForm()
UserForm1.Show
End Sub
' Then use an event to check controls on the form
' I connected a button to this Sub Process
Sub CountTBs()
For Each TB In UserForm1.Controls
If TB.Name Like "TextBox?" Then
tbCount = tbCount + 1
strTBVal = TB.Text
msgTxt = msgTxt & strTBVal & " - "
End If
Next
MsgBox msgTxt
End Sub
' In the project Explorer frame right-click
' the UserForm Object and Select "View Code"
' this is the code attached to the button
' to loop the controls by calling the CountTBs sub above
Private Sub CommandButton1_Click()
Call CountTBs
End Sub
.