Looping thru TextBoxes

  • Thread starter Thread starter John Pierce
  • Start date Start date
J

John Pierce

I am trying to get some code to run in a series of textboxes on a
form. I found the bit of code below from Tom Ogilvy which appears
to be able to do that. I put it on a code sheet with Public Sub
LoopthruTextboxes() in front and End Sub at the end and ran it.
The form opens on the screen but nothing else happens. I'm
guessing that cntrl is not a keyword but a variable that needs to
be defined as an object(?) When I get this working would I just put
the code I want to repeat in place of "MsgBox cntrl.Name"?

For Each cntrl In UserForm1.Controls
i = 0
If TypeOf cntrl Is MSForms.TextBox Then
i = i + 1
MsgBox cntrl.Name
End If
Next
 
The problem is where you put the code. Put it the UserForm_Click()
event and click on the form when it appears (or have the
UserForm_Click() event call your Sub).

Merjet
 
Back
Top