Strings in Variables

B

Bob Rice

I need to move through the objects of a form, making them visible (or
invisible). The objects are Box1, Box2, etc. I need to loop until they are
all visible.

For k = 1 To 3
Forms![My Form]!Boxk.Visible = True
Next

I can't get the correct syntax for "Boxk".

Need help.

I spend too much time fooling with &'s and single and double quatation
marks. Are there any safe rules of thumb for SQL and the like?
 
M

Matthias Klaey

I need to move through the objects of a form, making them visible (or
invisible). The objects are Box1, Box2, etc. I need to loop until they are
all visible.

For k = 1 To 3
Forms![My Form]!Boxk.Visible = True
Next

I can't get the correct syntax for "Boxk".
[...]

Forms![My Form].Controls("Box" & k).Visible = True

HTH
Matthias Kläy
 
G

Gerald Stanley

Given that the loop is 3 cycles, it would be more efficient to write
Forms![My Form]!Box1.Visible = True
Forms![My Form]!Box2.Visible = True
Forms![My Form]!Box3.Visible = True

For a large loop.the syntax would have been

For k = 1 To n
Forms![My Form].Controls("Box" & Cstr(k)).Visible = True
Next

Hope This Helps
Gerald Stanley MCSD
 
Top