Userform Controls

  • Thread starter Thread starter Nigel
  • Start date Start date
N

Nigel

Hi All
I have a set of controls on a userform, named x1, x2, x3 ........... xn etc

Is there a way of setting these controls in a loop eg

for i = 1 to n
set control x of i to something
next i

I am not sure how to point to a named control by constructing a string for
the name? Help!
 
Nigel,

As long as you have a structured naming convention, you could use code like
this that gets the value from each textbox on the form

Dim ctl As Control

For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Then
MsgBox ctl.Text
End If
Next ctl

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks Bob, that is part of the problem solved. My challenge is with a
subset of controls of the same type I wish to act on.

I have a set of code linked to controls named c1 to cn, an event from anyone
of these acts on another control named x1, x2 to xn etc.

Whichever control c1 to cn is pressed the same code for x1 to xn needs to
run. Somehow I need to pass the number of the cn control to the code to act
on the xn control.

Any thoughts?
 

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

Back
Top