473,796 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10117
dim ctl as control
for each ctl in ActiveForm.Cont rols
if ctl.Name <> "ComboIDoNotWan tDisabled" Then
ctl.visible=fal se
else
ctl.visible=tru e
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*********@hot mail.com
http://amazecreations.com/datafast/

"lylefair" <ly***********@ aim.com> wrote in message news:11******** *************@g 49g2000cwa.goog legroups.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 "hypnotizin g 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******** *************@g 14g2000cwa.goog legroups.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 "hypnotizin g 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********@com putunity.com> wrote in
news:11******** **************@ g47g2000cwa.goo glegroups.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.ControlTyp e = 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 ShowHideControl s(bolShow As Boolean)
Dim ctl As Control

For Each ctl In Me.Controls
If (ctl.ControlTyp e = 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 ShowHideControl s(Not IsNull(Me!MyCom boBox))

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 ShowHideControl s(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.Ad d 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 InitializeShowH ideCollection()
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.Ad d ctl, ctl.Name
Next ctl
Set ctl = Nothing
End If
End Sub

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

Call InitializeShowH ideCollection

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

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

Call InitializeShowH ideCollection
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

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

Similar topics

3
5562
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 an array-variable and pass this variable to a subroutine in which I make all stored objects in the array-variable invisible. Can somebody explain me how to declare the correct variables, how to pass these to a sub routine and how to make these...
3
6827
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 frmTrialInfo. Each Trial can have three Classes. The third form is frmClassInfo. These forms are used for update and adding new records. The user displays an event for update (frmEventAdd). Then clicks on a button to display the Trials for that event...
3
4891
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 I follow the tips of MSDN making a new class with an instance of the form that has the logical of the application. But it not run since I call the ShowDialog() method. Please, can anyone gime me a tip or any web with an example? I´m a newbie.
9
2084
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 working with StatusBar.Text? Thanks in Advance, Christian Blackburn My Code: Public Class frmMain
6
1401
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. cform = New frmClients cform.Visible = False ' this does not seem to make form hidden (not visible) cform.TopLevel = False
16
2159
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 Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then
6
2609
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 that is bound to a table and has no duplicates allowed. the problem is that there are 30 or so other controls here to be filled in and if the user selects a year and month that already has a record created, she/he won't know it until access tries to...
2
1384
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 make form2 visible once and make it invisible again, although it should be staying active in memory. If I have a global boolean g_form2Shown then to show it I can, in a click event in form1 do If not g_Form2Shown then Form2.show 'the declaration...
2
1487
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) they are visible or invisible If PropCD820 = vbChecked Then PriceCD820.Visible = False Else PriceCD820.Visible = True End If
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.