View Full Version : Control names


BadScript
12-21-2007, 06:18 AM
I tried to search this forum but so far no results. If this question was already asked I apologise. In my VB I use the following script.
I was wondering if there's a way to make this script shorter


lbl13.Visible = False
lbl14.Visible = False
lbl15.Visible = False
lbl16.Visible = False
lbl17.Visible = False
lbl18.Visible = False
lbl19.Visible = False
lbl20.Visible = False
lbl21.Visible = False
lbl22.Visible = False
lbl23.Visible = False

Uncle Gizmo
12-21-2007, 06:53 AM
Yes you can loop through the controls collection in the form and then modify a particular control according to some key value associated with that control.

Typically you can prefix the names of the controls you want to modify like this: lblX13 then your code is designed to detect the "X" and modify controls marked Thus accordingly.

You could alternatively add a value within the tag property detect this value and take action accordingly.

The code you would use would be something like this:

Dim Ctl as Control

For Each Ctl in me.controls
if Ctl.tag = "X" then Ctl.Visible = False
Next Ctl

Uncle Gizmo
12-21-2007, 06:57 AM
there is quite a comprehensive thread on it here: (http://www.access-programmers.co.uk/forums/showthread.php?t=137870)

BadScript
12-21-2007, 08:53 AM
Thanks alot !
I'm a beginner and this will make it alot easier for me :)