Looping thru TextBoxes

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
 
M

merjet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top