Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set all objects in a form to invisible.

2 views
Skip to first unread message

Cy

unread,
Oct 9, 2005, 4:56:44 PM10/9/05
to
I've had good luck with posting in the past, so we'll see how things go
this time...:)

I have an Access 2000 form. On the form is about 40 objects. I want
to set everything to invisible, except a drop down box. Once the user
selects from the pull down menu, I have code that picks the applicable
fields to be visible.

Thus, if a user makes changes to the pull down menu, ie. changes the
value in the pull down, I need everything to go back to being invisible
and a new set of objects appear.

Any ideas on how to set all 40 objects to invisible without having to
call each individual object in code?

pietl...@hotmail.com

unread,
Oct 9, 2005, 5:07:08 PM10/9/05
to
dim ctl as control
for each ctl in ActiveForm.Controls
if ctl.Name <> "ComboIDoNotWantDisabled" Then
ctl.visible=false
else
ctl.visible=true
end if
next ctl

lylefair

unread,
Oct 9, 2005, 9:27:11 PM10/9/05
to
Check with Lamont Cranston.

Danny J. Lesandrini

unread,
Oct 9, 2005, 9:53:10 PM10/9/05
to
I thought Lamont was the Shadow, not the Invisible Man

--

Danny J. Lesandrini
dlesa...@hotmail.com
http://amazecreations.com/datafast/

"lylefair" <lylefa...@aim.com> wrote in message news:1128907631....@g49g2000cwa.googlegroups.com...
> Check with Lamont Cranston.
>


lylefair

unread,
Oct 9, 2005, 9:57:01 PM10/9/05
to
You are very young, Danny!

Danny J. Lesandrini

unread,
Oct 9, 2005, 9:58:22 PM10/9/05
to
Get outta town! Are you telling me Lamont Cranston ISNT The Shadow?


lylefair

unread,
Oct 9, 2005, 10:34:19 PM10/9/05
to
Not really. The Shadow may have been a flyer named Allard who crashed
and who was presumed dead, but assumed the identity of Cranston. But,
Allard's body was later found, so, nobody knows exactly who the Shadow
was or is. But he knew the evil that lurks in the hearts of men, so
everything is OK. And the Shadow, in his later adventures could become
invisible, by "hypnotizing men's minds". (I plan to teach this skill to
David!).
I always wondered if Lamont could become invisible while he was making
love to Margo(t) Lane and what she might have thought of that?

PC Datasheet

unread,
Oct 10, 2005, 12:06:28 AM10/10/05
to
Lamont was never able to become totally invisible at that moment no matter
how hard (sic) he tried. He could only set an object to invisible.

Steve


"lylefair" <lylefa...@aim.com> wrote in message

news:1128911659....@g14g2000cwa.googlegroups.com...

David W. Fenton

unread,
Oct 10, 2005, 3:21:15 PM10/10/05
to
"Cy" <googl...@computunity.com> wrote in
news:1128891404.8...@g47g2000cwa.googlegroups.com:

I'm obviously not getting the joke that the others are engaging in,
so I'll actually take you seriously and answer your question.

The best way to change a group of controls is to loop through the
form's controls collection and set properties of those controls.
You'll need some way of identifying which controls you want to act
upon, so I usually use the .Tag property. However, if you want all
controls except the one combo box, you could select on controltype
and name. That would look something like this:

Dim ctl As Control

For Each ctl In Me.Controls
If (ctl.ControlType = acComboBox _
Or ctl.ControlType = acTextBox) _
And ctl.Name <> "MyComboBox" Then
ctl.Visible = True
End If
Set ctl = Nothing
Next ctl

Now, you could wrap that in a subrouting that you pass a Boolean
argument that controls whether you're revealing or hiding:

Private Sub ShowHideControls(bolShow As Boolean)
Dim ctl As Control

For Each ctl In Me.Controls
If (ctl.ControlType = acComboBox _
Or ctl.ControlType = acTextBox) _
And ctl.Name <> "MyComboBox" Then
ctl.Visible = bolShow
End If
Next ctl
Set ctl = Nothing
End Sub

Then you could call that in the AfterUpdate event of your combo box
thus:

Call ShowHideControls(Not IsNull(Me!MyComboBox))

That would reveal everything as long as the combo box is not null,
and hide everything when it's Null.

Now, if you used the .Tag property instead, it would look like this:

Private Sub ShowHideControls(bolShow As Boolean)
Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "ShowHide" Then
ctl.Visible = bolShow
End If
Next ctl
Set ctl = Nothing
End Sub

Now, walking the entire controls collection every time you do this
is actually a pretty slow operation, so for something like this, I
always use a custom collection. You populate that collection in the
OnLoad event of the form, and then use the collection for
showing/hiding. To populate the collection:

Dim ctl As Control

If (mcolShowHide Is Nothing) Then
Set mcolShowHide = New Collection
For Each ctl In Me.Controls
If ctl.Tag = "ShowHide" Then mcolShowHide.Add ctl, ctl.Name
Next ctl
Set ctl = Nothing
End If

One point: mcolShowHide should be declared at the form's module
level:

Private mcolShowHide As Collection

Now, you also might wonder why I'm checking for Is Nothing in the
form's OnLoad event. It's obviously not necessary there, but I
included it because it's better to put this routine in its own
subroutine so you can call it before using the collection (so that
you're sure the collection has been initialized). So, that would
look something like this:

Private Sub InitializeShowHideCollection()
Dim ctl As Control

If (mcolShowHide Is Nothing) Then
Set mcolShowHide = New Collection
For Each ctl In Me.Controls
If ctl.Tag = "ShowHide" Then mcolShowHide.Add ctl, ctl.Name
Next ctl
Set ctl = Nothing
End If
End Sub

Now, you'd call that in the OnLoad event as:

Call InitializeShowHideCollection

Now, to use it, you'd define your ShowHideControls subroutine as
this:

Private Sub ShowHideControls(bolShow As Boolean)
Dim varCtl As Variant
Dim ctl As Control

Call InitializeShowHideCollection
For Each varCtl In mcolCollection
Set ctl = varCtl
ctl.Visible = bolShow
Next varCtl
Set ctl = Nothing
End Sub

You'll find that this is *much* faster noticeably so, than walking
the entire controls collection because there are a lot more controls
on the form than you think (remember that every label, every command
button, every line, every box is a control), and the time it takes
to test for the name or tag or ControlType accumulates when you loop
through that many items.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Danny J. Lesandrini

unread,
Oct 10, 2005, 3:30:22 PM10/10/05
to
David:
Your answer is conprehensive, but the answer posted yesterday, 11 minutes
after the question was logged, was sufficient to solve Cy's problem. Not
that your contribution isn't welcome, but the suggestion that the question
wasn't taken seriously is in error. It was seriously answered, and then we
had our fun.
--
Danny J. Lesandrini


David W. Fenton

unread,
Oct 10, 2005, 11:56:00 PM10/10/05
to
"Danny J. Lesandrini" <dlesa...@hotmail.com> wrote in
news:BM2dneqHGsnLXNfe...@comcast.com:

There is no serious answer to the question on my news server. I
checked before responding, as I didn't want to spend that time if
someone had already answered it.

0 new messages