472,364 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

Set all objects in a form to invisible.

Cy
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?

Nov 13 '05 #1
10 9829
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

Nov 13 '05 #2
Check with Lamont Cranston.

Nov 13 '05 #3
I thought Lamont was the Shadow, not the Invisible Man

--

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

"lylefair" <ly***********@aim.com> wrote in message news:11*********************@g49g2000cwa.googlegro ups.com...
Check with Lamont Cranston.

Nov 13 '05 #4
You are very young, Danny!

Nov 13 '05 #5
Get outta town! Are you telling me Lamont Cranston ISNT The Shadow?
Nov 13 '05 #6
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?

Nov 13 '05 #7
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" <ly***********@aim.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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?

Nov 13 '05 #8
"Cy" <go********@computunity.com> wrote in
news:11**********************@g47g2000cwa.googlegr oups.com:
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?


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
Nov 13 '05 #9
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
Nov 13 '05 #10
"Danny J. Lesandrini" <dl*********@hotmail.com> wrote in
news:BM******************************@comcast.com:
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.


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.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SV | last post by:
Dear all, In my application I have a lot of hidden fields. I want to make them invisible for the users though for debugging reasons I want to make them visible. So I want to add these objects to...
3
by: Susan Bricker | last post by:
Greetings. I have three forms that are open at the same time. They are related and cascading. The first form (frmEventAdd) is the anchor. Each event can have many Trials. The second form is...
3
by: Jose_Csharp | last post by:
Hi guys, Im trying to make a startup invisible form. I dont want a form with Opacity property 0. First I did the property Visible of the form to false. It wasnt a good idea, was too easy. Then...
9
by: Christian Blackburn | last post by:
Hi Gang, I've had this happen with a couple of controls now, but my patience has worn thin. Can somebody tell me why I can read/write to most objects on my form from my module, but not when...
6
by: John | last post by:
Hi Is there a way to open a form hidden/invisible while it is populating its controls, and then make it visible once it is done? I am using the following code but the form remains visible. ...
16
by: AJPlonka | last post by:
Can anyone tell me why this doesn't start hidden? Public Class Form1 Inherits System.Windows.Forms.Form Public Sub New() MyBase.New() InitializeComponent() End Sub Protected Overloads...
6
by: kaosyeti | last post by:
hey.... i have a duplicate record issue i could use some help with. on a form that has 2 unbound controls, txtboxyear and cboxmonth, together will automatically fill in an invisible txtboxdate...
2
by: Robert Dufour | last post by:
I have Form1 and Form2. Form2 has to be loaded in memory so that controls on it can be controlled from Form1, so I declared it in the Form1 declaration section. That works OK. Now I just need to...
2
by: layhan | last post by:
I have a form with a list of OLE objects imported from Excel (they might as well be images or labels, doesn't matter.) Form_Current() is set up so when a check box is ticket (one for each object)...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.