
Originally Posted by
MarkT
See if this helps
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim pic As PictureBox
For i = 1 To 3
Set pic = Controls("Picture" & i)
pic.Visible = Not pic.Visible
Next i
End Sub
You don't need the variable; controls can be accessed by name directly.
Code:
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 3
Me("Picture" & i).Visible = False
Next
End Sub
EDIT: Though in looking back at this I'm guessing you already know this and only used a variable because you're referencing the control twice. (Visible = Not Visible) I suppose if you wanted to keep the code clean and save a variable you could use a With...End With block.