Naming multiple controls

G

Guest

Is it possible to assign a common name to more than one control and then
change a given property for that group of controls?

For example, a number of controls may be hidden. On an event - say OnClick
for a button - these controls all become visible. Instead of setting the
..visible property for each control individually, I'd like to set the .visible
property for a named group in one go.

Is this possible? The Tag property doesn't seem to provide the answer.
 
G

Guest

Not that I've seen. You might be able to do it to a FRAME control and its
associated checkboxes/radio buttions though. But you have something against
writing code? I mean, really, you only have to write the code once...
 
G

Guest

Fair point, Dennis.

I am just at the start of programming a large number of forms, most of which
will need large numbers of controls to behave simultaneously and I thought I
might save some time. Also, the project is subject to a lot of change
(management changing their minds) and so I am sadly not going to write code
"only once". I'll be doing it again and again as my masters' minds change...

Tried the option frame thing, but with little joy. A neater way of doing it
is with tab controls. Don't actually use the tabs, just place everything on
the tab control, set Style to "None" (i.e. neither buttons nor tabs, which
removes the ugly and uneditable grey strip) and then hide the tab control.
It's just not as tight, programatically, as I'd like it. I'd hoped there to
be a "proper" way of doing it.
 
B

BruceM

You don't say how you use the Tag property, but if the Tag is Vis for each
of those controls you could do something like:

Dim ctl as Control

For Each ctl in Me.Controls
If ctl.Tag = "Vis" Then
ctl.Visible = Not ctl.Visible
end if
Next ctl

This will toggle the visible property. If that's not what you want you can
just have:
ctl.Visible = False
instead of:
ctl.Visible = Not ctl.Visible

I don't think you can do anything with the properties of a named group along
the lines of what you have requested, but as an alternative to the above you
may be able to do something such as showing or hiding a box that covers the
controls, or moving the controls forward or backward, or something like
that.
 
M

Marshall Barton

Rod said:
Is it possible to assign a common name to more than one control and then
change a given property for that group of controls?

For example, a number of controls may be hidden. On an event - say OnClick
for a button - these controls all become visible. Instead of setting the
.visible property for each control individually, I'd like to set the .visible
property for a named group in one go.

Is this possible? The Tag property doesn't seem to provide the answer.


You could stretch a tab control to do something like that.
It might be a lot of workm but you could use a subform to
contain those controls.

However, the Tag property makes it easy to write a procedure
to do it without any trickery.

Sub ShowHide(frm As Form, Grp As String, OnOff As Boolean)
Dim ctl As Control
For Each ctl In frm.Controls
If ctl.Tag = Grp Then
ctl.Visible = OnOff
End If
Next ctl
End Sub

Then you can create group A of controls by setting their Tag
property to A

And hide them using:

ShowHide Me, "A", False
 

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