473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 10049
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, I´m trying to make a startup invisible form. I don´t want a form with Opacity property 0. First I did the property Visible of the form to false. It wasn´t 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)...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.