Array of Controls...

Array of Controls...

Anonymous
Not applicable
304 Views
5 Replies
Message 1 of 6

Array of Controls...

Anonymous
Not applicable
In VB6 I can create an array of controls, like a textbox(0 to 6), but I cant
do that on a vba form...
If I have a group of similar controls (textbox1, textbox2, textbox3) how can
I loop through them
with this type of code:

for x = 1 to 3
var = userform1.textbox(x).value
next

Rodney
0 Likes
305 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Hi Rodney

Use the Frame control and place the other controls inside. Then you can loop
through the controls like you want.

Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch


"Rodney D. Lester" schrieb:
>
> In VB6 I can create an array of controls, like a textbox(0 to 6), but I cant
> do that on a vba form...
> If I have a group of similar controls (textbox1, textbox2, textbox3) how can
> I loop through them
> with this type of code:
>
> for x = 1 to 3
> var = userform1.textbox(x).value
> next
>
> Rodney
0 Likes
Message 3 of 6

Anonymous
Not applicable
The controls are in a frame... What is the code to loop through them...
My sample code does not work...

Rodney

"Jürg Menzi" wrote in message
news:3B7D154D.38D7825D@bluewin.ch...
> Hi Rodney
>
> Use the Frame control and place the other controls inside. Then you can
loop
> through the controls like you want.
>
> Cheers
> --
> Juerg Menzi
> MENZI ENGINEERING GmbH, Switzerland
> http://www.menziengineering.ch
>
>
> "Rodney D. Lester" schrieb:
> >
> > In VB6 I can create an array of controls, like a textbox(0 to 6), but I
cant
> > do that on a vba form...
> > If I have a group of similar controls (textbox1, textbox2, textbox3) how
can
> > I loop through them
> > with this type of code:
> >
> > for x = 1 to 3
> > var = userform1.textbox(x).value
> > next
> >
> > Rodney
0 Likes
Message 4 of 6

Anonymous
Not applicable
Hi Rodney

For x = 0 to (NumberOfControls -1)
Var = FrameName(x).Value
Next x

That's it...

Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch


"Rodney D. Lester" schrieb:
>
> The controls are in a frame... What is the code to loop through them...
> My sample code does not work...
0 Likes
Message 5 of 6

Anonymous
Not applicable
How do I know which control I am getting with the X index?

Rodney

"Jürg Menzi" wrote in message
news:3B7D3C41.19893C06@bluewin.ch...
> Hi Rodney
>
> For x = 0 to (NumberOfControls -1)
> Var = FrameName(x).Value
> Next x
>
> That's it...
>
> Cheers
> --
> Juerg Menzi
> MENZI ENGINEERING GmbH, Switzerland
> http://www.menziengineering.ch
>
>
> "Rodney D. Lester" schrieb:
> >
> > The controls are in a frame... What is the code to loop through them...
> > My sample code does not work...
0 Likes
Message 6 of 6

Anonymous
Not applicable
Randal Rath at VbDesign has a routine that works by assigning the 'index number'
to the control's tag property. Then you can loop through the controls and check
the 'tag' value to know which control it is working on. Silly that vba does not
support control arrays.
Go to his web site and look around, the routine is there somewhere.

Tom

"Rodney D. Lester" wrote:

> In VB6 I can create an array of controls, like a textbox(0 to 6), but I cant
> do that on a vba form...
> If I have a group of similar controls (textbox1, textbox2, textbox3) how can
> I loop through them
> with this type of code:
>
> for x = 1 to 3
> var = userform1.textbox(x).value
> next
>
> Rodney
0 Likes