Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variables to refer to control names

Status
Not open for further replies.

mlittman

Technical User
Nov 27, 2001
3
US
I have 10 groups of controls on a report, and each group has 8 controls. I have labeled them in an array fashion: "vhs1field1","vhs1field2",.. "vhs[ i ]field[ j ]".
I want to be able to modify all of the fields in a single code loop, based on an associated yes/no button on another form. However, I cannot figure out the correct syntax. Here's what I am trying:

Dim I As Integer, J As Integer
Dim strLabel As String, strTapeNo As String

For I = 1 To 10 ' 10 labels per form
strTapeNo = "[Forms]![vhs_pick_label]![vhs" & I & "]"

For J = 1 To 8 ' 8 fields of interest
strLabel = "vhs" & I & "field" & J
Me![(strLabel)].Visible = Not ([(strTapeNo)])
Next J

Next I

For example, if the button for label 2 is deselected, the
report should cause controls 1-8 for that label to be
not visible.

The above syntax does NOT work, and I have tried many different variants.
Is it even possible to refer to controls using variables?
Thanks for any help!!
 
If you figure it out, I'd like to know too! I tried to do something similar a few weeks ago and couldn't get it to work. I posted some messages somewhere on this website related to this issue, but nobody came up with a way to do it. I suspect that it can't be done, but I'm not sure. I'll post a link to the other thread if I can find it.
 
Is there not a Controls collection as in VB6.
Dim ctlLabel As Control
For J = 1 To 8 ' 8 fields of interest
strLabel = "vhs" & I & "field" & J
Set ctlLabel = Me.Controls(strLabel)
ctlLabel.Visible = .....
Next J
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
The controls collection worked real well, that's the solution!!
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top