Using a variable to refer to a control in VBA

D

Dale K

Good Afternoon,

I was wondering if any one can tell me how to fix the 3rd line to work like
the 2nd one does. The 2nd one works fine but one the 3rd one they system
throws an error.

thanks!

Dale

Dim intloop as integer
intloop=8
Forms![frmDate]![frmsubMonth].Form![subForm8].visible = False
Forms![frmDate]![frmsubMonth].Form!("subFrom" & intloop & "").visible = False
 
P

PieterLinden via AccessMonster.com

Dale said:
Good Afternoon,

I was wondering if any one can tell me how to fix the 3rd line to work like
the 2nd one does. The 2nd one works fine but one the 3rd one they system
throws an error.

thanks!

Dale

Dale,
How about ...
Basically, inside the parens is a string value: the text part of the name and
then you append the subscript of the form. Then you can manipulate the
visible property from there.
HTH,
Pieter

Private Sub Command14_Click()

Dim intLoop As Integer
For intLoop = 1 To 3
Me.Form("sfrmChoices" & intLoop).Visible = Not (Me.Form("sfrmChoices"
& intLoop).Visible)
Next intLoop

End Sub
 
J

John W. Vinson

Good Afternoon,

I was wondering if any one can tell me how to fix the 3rd line to work like
the 2nd one does. The 2nd one works fine but one the 3rd one they system
throws an error.

thanks!

Dale

Dim intloop as integer
intloop=8
Forms![frmDate]![frmsubMonth].Form![subForm8].visible = False
Forms![frmDate]![frmsubMonth].Form!("subFrom" & intloop & "").visible = False

Assuming that frmSubMonth is a Subform control, and that somewhere on that
control is a sub-subform named subForm8, try

Forms![frmDate]![frmsubMonth].Form.Controls("subForm" & intloop).visible =
False

I presume that subFrom for subForm was a typo (having made that typo many
times myself...)
 

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

Top