By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,078 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,078 IT Pros & Developers. It's quick & easy.

Making a lot of stuff Visible and not Visible on a Form

P: n/a
Hi

I have a form with multiple labels and textboxes and listboxes that
need to be made visible and not visible when buttons are clicked. Is
there anyway of grouping them together so that I have less lines of
code instead of 100's of lines stating:

LblA.Visible = True
LblB.Visible = True
LblC.Visible = True
LblD.Visible = True
LblE.Visible = True
LblF.Visible = True ..etc., etc. and then making them not visible
again at a later stage and thus repeating the same lines of code?

By default Visible = False for most of the objects on the form.

Thanks

Mar 3 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
There are a few ways to tackele this.

1) if you labels are named in the way you list them then you could do

dim intX as integer

For intX = 65 to 70
Me.Control("Lbl" & Chr(intx)).Visible = True
Next

The easier way to do this is to name your controls with a number at the end
so say you had

Lbl1,
Lbl2,
Lbl3

You could go

For intX = 1 to 3
Me.Control("Lbl" & Chr(intx)).Visible = True
Next

Another way would be to use the Tag property.

So say you group a bunch of controls by setting the tag property of each of
then to "<<cond1>>"

You could then do this

Dim ctl as Control

For each ctl in Me.Controls
if ctl.Tag = "<<cond1>>" Then
ctl.Visible = false
end if
next

You could then get a bit more subtle and add multiple values in the Tag
property to check against different conditions giving you different
groupings.

--

Terry Kreft
"Hansen" <he******@hotmail.com> wrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...
Hi

I have a form with multiple labels and textboxes and listboxes that
need to be made visible and not visible when buttons are clicked. Is
there anyway of grouping them together so that I have less lines of
code instead of 100's of lines stating:

LblA.Visible = True
LblB.Visible = True
LblC.Visible = True
LblD.Visible = True
LblE.Visible = True
LblF.Visible = True ..etc., etc. and then making them not visible
again at a later stage and thus repeating the same lines of code?

By default Visible = False for most of the objects on the form.

Thanks

Mar 3 '06 #2

P: n/a
On Fri, 3 Mar 2006 13:11:38 -0000, "Terry Kreft"
<te*********@mps.co.uk> wrote:

Rather than:
Chr(intx)
use:
CStr(intx)

-Tom.

There are a few ways to tackele this.

1) if you labels are named in the way you list them then you could do

dim intX as integer

For intX = 65 to 70
Me.Control("Lbl" & Chr(intx)).Visible = True
Next

The easier way to do this is to name your controls with a number at the end
so say you had

Lbl1,
Lbl2,
Lbl3

You could go

For intX = 1 to 3
Me.Control("Lbl" & Chr(intx)).Visible = True
Next

Another way would be to use the Tag property.

So say you group a bunch of controls by setting the tag property of each of
then to "<<cond1>>"

You could then do this

Dim ctl as Control

For each ctl in Me.Controls
if ctl.Tag = "<<cond1>>" Then
ctl.Visible = false
end if
next

You could then get a bit more subtle and add multiple values in the Tag
property to check against different conditions giving you different
groupings.


Mar 3 '06 #3

P: n/a
Thanks Guys

Will try these approaches this weekend!

Mar 3 '06 #4

P: n/a
How about something like:
dim ctl
for each ctl in Array(lbl1, lbl2, ..., txtWhatever)
ctl.visible = true
next ctl

Mar 3 '06 #5

P: n/a
"Hansen" <he******@hotmail.com> wrote in
news:11*********************@p10g2000cwp.googlegro ups.com:
I have a form with multiple labels and textboxes and listboxes
that need to be made visible and not visible when buttons are
clicked. Is there anyway of grouping them together so that I have
less lines of code instead of 100's of lines stating:

LblA.Visible = True
LblB.Visible = True
LblC.Visible = True
LblD.Visible = True
LblE.Visible = True
LblF.Visible = True ..etc., etc. and then making them not visible
again at a later stage and thus repeating the same lines of code?

By default Visible = False for most of the objects on the form.


When I need to do this kind of thing, I use a custom collection (or
several of them) make this more efficient. I use the controls' .Tag
property to group them, and walk the Controls collection to set up
the collections.

1. assign appropriate .Tag properties, a unique value for each group
of controls (e.g., "label" for all your labels, "combo" for combo
boxes, "checkbox" for Checkboxes; these are examples since all of
these are things you could find out from checking the ControlType).

2. in the OnLoad event of your form, loop through the Controls
collection and populate your collections, using either the .Tag
property or the .ControlType to determine which collection to assign
them to.

3. once you've done that, then you can loop through each collection
of controls and change properties any way you like.

I've posted more detailed instructions on how to accomplish this in
the past. If you search Google Groups in this newsgroup for my name
and "custom collection" you are likely to be able to find pretty
explicit instructions for how to accomplish the above tasks.

I only use custom collections, though, when I want to switch things
on and off multiple times in a form session. If I just wanted to set
up the form when opening it, I'd just walk the controls collection
and do it once.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Mar 3 '06 #6

P: n/a
bob
How about using different TABS and then dropping whatever controls you like
on them...and setting them to visible..

or even a subform or a few and make them visible based on something else?

"Hansen" <he******@hotmail.com> wrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...
Hi

I have a form with multiple labels and textboxes and listboxes that
need to be made visible and not visible when buttons are clicked. Is
there anyway of grouping them together so that I have less lines of
code instead of 100's of lines stating:

LblA.Visible = True
LblB.Visible = True
LblC.Visible = True
LblD.Visible = True
LblE.Visible = True
LblF.Visible = True ..etc., etc. and then making them not visible
again at a later stage and thus repeating the same lines of code?

By default Visible = False for most of the objects on the form.

Thanks

Mar 4 '06 #7

P: n/a
"Hansen" <he******@hotmail.com> wrote in
news:11*********************@p10g2000cwp.googlegro ups.com:
Hi

I have a form with multiple labels and textboxes and listboxes
that need to be made visible and not visible when buttons are
clicked. Is there anyway of grouping them together so that I
have less lines of code instead of 100's of lines stating:

LblA.Visible = True
LblB.Visible = True
LblC.Visible = True
LblD.Visible = True
LblE.Visible = True
LblF.Visible = True ..etc., etc. and then making them not
visible again at a later stage and thus repeating the same
lines of code?

By default Visible = False for most of the objects on the
form.

Thanks

If labels for other controls are actually bound to their
controls, you don't need to worry about the labels, they follow
the control's .visible property.

A snippet from a filter form that has a checkbox labelled
"Filter by Date"

private sub DatesVisible(bShowDates as boolean)
txtOpenFromdate = bShowdates
txtOpenTodate = bshowdates.
txtClosedFromDate = bShowdates
txtClosedToDate = bShowdates
end sub

'the afterupdate event of the control sets the var and calls the
datesvisible sub.

if me.FilterByDates.value then
bshowdates true
else
bshowdates false
endif

--
Bob Quintal

PA is y I've altered my email address.
Mar 4 '06 #8

P: n/a
Yes, I spotted that when re-reading, thanks for the catch Tom.

--

Terry Kreft
"Tom van Stiphout" <no*************@cox.net> wrote in message
news:r7********************************@4ax.com...
On Fri, 3 Mar 2006 13:11:38 -0000, "Terry Kreft"
<te*********@mps.co.uk> wrote:

Rather than:
Chr(intx)
use:
CStr(intx)

-Tom.

There are a few ways to tackele this.

1) if you labels are named in the way you list them then you could do

dim intX as integer

For intX = 65 to 70
Me.Control("Lbl" & Chr(intx)).Visible = True
Next

The easier way to do this is to name your controls with a number at the endso say you had

Lbl1,
Lbl2,
Lbl3

You could go

For intX = 1 to 3
Me.Control("Lbl" & Chr(intx)).Visible = True
Next

Another way would be to use the Tag property.

So say you group a bunch of controls by setting the tag property of each ofthen to "<<cond1>>"

You could then do this

Dim ctl as Control

For each ctl in Me.Controls
if ctl.Tag = "<<cond1>>" Then
ctl.Visible = false
end if
next

You could then get a bit more subtle and add multiple values in the Tag
property to check against different conditions giving you different
groupings.

Mar 6 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.