concatenate

J

john

is it possible to concatenate a control in vb like you
would a string? i have many controls on a report and i
was wondering if i could set up a loop to do the work for
me, instead of naming each control in code.
 
D

Douglas J. Steele

If, say, you've got controls Text1, Text2, Text3, ... Textn, you can do
something like:

Dim ctlCurr As Control
Dim intLoop As Integer

For intLoop = 1 to n
Set ctlCurr = Me.Controls("Text" & intloop)
' Use ctlCurr however you want
Next intLoop
 
S

Sandra Daigle

Hi John,

Not sure if this is what you mean but lets say you have textboxes "Text1",
"Text2" and "Text3" and you want to set the visible property to false for
each. You could say:

me.Text1.visible=false
me.Text2.visible=false
me.Text3.visible=false

or you could do it this way:

dim inti as integer
for inti = 1 to 3
me.controls("Text" & inti).visible=false
next inti

Granted, for 3 controls there isn't any code savings!

Or, to loop through all controls,

dim ctl as control
for each ctl in me.controls
ctl.visible=false
next ctl
set ctl = nothing
 
M

MarkD

in addition to the above responses, you can loop through
all controls

Dim ctl As Control
For Each ctl In Me.Controls
'do stuff here
Debug.Print ctl.Name
Next ctl

you can filter on control name, control type, etc, control
tag. Probably not what you're looking for, but it's been
useful for me in many situations.
 
Top