473,486 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Make a Label Box Visible if Yes/No value is Checked

1 New Member
Is there anyone who can help me regarding the above subject?

My situation is that I have a field (with property set as as Yes/No) and I would like to use this to activiate the visibility of another field.

For example:

A student is a foreigner, he will mark the box checked (Are you a Foreigner?)then a label will appear beside it where he can put his nationality.

Thanks a lot...
Dec 16 '07 #1
7 16453
ADezii
8,834 Recognized Expert Expert
Is there anyone who can help me regarding the above subject?

My situation is that I have a field (with property set as as Yes/No) and I would like to use this to activiate the visibility of another field.

For example:

A student is a foreigner, he will mark the box checked (Are you a Foreigner?)then a label will appear beside it where he can put his nationality.

Thanks a lot...
Assuming your Controls are named chkForeigner and txtNationality, then, in the AfterUpdate() Event of chkForeigner:
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkForeigner_AfterUpdate()
  2. If Me![chkForeigner] Then
  3.   Me![txtNationality].Visible = True
  4. Else
  5.   'No Nationality should be listed if not a Foreigner
  6.   Me![txtNationality] = Null
  7.   Me![txtNationality].Visible = False
  8. End If
  9. End Sub
Additional points to consider:
  1. The Visible Property of txtNationality should initially be set to No in the Control's Properties.
  2. For Viewing purposes, you may also wish to place this code in the Form's Current() Event. If the individual is a Foreigner, then the Nationality Text Box will be visible, if he/she is not, then it won't.
Dec 16 '07 #2
missinglinq
3,532 Recognized Expert Specialist
First off, your user cannot enter data in a "label box," data is entered in a textbox!

Place a textbox on your form.

Select it and goto Properties - Format and set the Visible Property to No.

Now place this code in the code module of your form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub AreYouAForeignerCheckBox_AfterUpdate()
  2. If AreYouAForeignerCheckBox = -1 Then
  3.  Me.NationalityTextBox.Visible = True
  4.  Me.NationalityTextBox.SetFocus
  5. Else
  6.  Me.NationalityTextBox = ""
  7.  Me.NationalityTextBox.Visible = False
  8. End If
  9. End Sub
  10.  
  11. Private Sub Form_Current()
  12.  If AreYouAForeignerCheckBox = -1 Then
  13.  Me.NationalityTextBox.Visible = True
  14. Else
  15.  Me.NationalityTextBox.Visible = False
  16. End If
  17. End Sub
  18.  
This code does what you've requested and makes the textbox visible then sets focus on it, and if the user realizes that he/she has made a mistake and unchecks the box, it empties the data from the NationalityTextBox then makes it invisible again.

Welcome to TheScripts!

Linq ;0)>
Dec 16 '07 #3
missinglinq
3,532 Recognized Expert Specialist
Didn't mean to steps on your toes, ADezii! Clicked on Submit and took "Puck the Magic Chow Hound" out for his morning stroll, got back and saw that it had timed-out. Didn't think to see if anyone else had answered, just clicked again!

Linq ;0)>
Dec 16 '07 #4
ADezii
8,834 Recognized Expert Expert
Didn't mean to steps on your toes, ADezii! Clicked on Submit and took "Puck the Magic Chow Hound" out for his morning stroll, got back and saw that it had timed-out. Didn't think to see if anyone else had answered, just clicked again!

Linq ;0)>
Never a problem, linq.
Dec 16 '07 #5
NeoPa
32,556 Recognized Expert Moderator MVP
You have two perfectly good examples of the type of code you need here. In essence, you simply set the .Visible property of your TextBox (not label) control to the CheckBox value. If the CheckBox is checked then .Visible will be set to TRUE, otherwise it will be set to FALSE.
Dec 17 '07 #6
ADezii
8,834 Recognized Expert Expert
You have two perfectly good examples of the type of code you need here. In essence, you simply set the .Visible property of your TextBox (not label) control to the CheckBox value. If the CheckBox is checked then .Visible will be set to TRUE, otherwise it will be set to FALSE.
Linq and I come from the same part of the Country, and consequently think alike to the point that it is almost scary! (LOL).
Dec 17 '07 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Forget 'Almost' ADezii ;)
Dec 17 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
8521
by: dcstech | last post by:
I have a label that will not display. On the form load event I wrote "label1.visible=false". when my routine get at the end of the code I inserted "label1.visible=true". I have had a similar...
1
4186
by: PCB | last post by:
Hi all, Not sure if this is possible, but can I change the controls of a command button on a per record bases in a subform. In my case, I would like to make a command button visible only if...
3
6803
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...
7
8554
by: Dave | last post by:
I have a button on Form1 that hides the form and displays Form2: Form2 myForm2 = new Form2(); myForm2.Show(); this.Hide(); After I do some work in Form2 I want to close it and redisplay...
4
4679
by: M Shafaat | last post by:
Hi! How can I make label, linklabel . controls to accept multilined text at design time and in the properties window of Visual Studio? Regards M Shafaat
4
10915
by: Gibs | last post by:
Hi, How can i make a label visible/invisible? I am able to do it for text box by using document.form1.TextBox1.style.visibility="hidden"; But when i am giving the same for the label, i am getting...
6
14671
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm...
1
1756
by: Beffmans | last post by:
hi I am trying to make this label visible through a checkbox. I try to make use of javascript but what am I doing wrong? <HTML> <HEAD> <title>WebForm1</title> <script>
4
2004
by: stevewy | last post by:
If I am using srcElement (or "target" for non-IE models) to return various properties of an object I have clicked on, can I access for "label for" value in any way? I'm thinking, for example, of...
4
24432
by: pradeep | last post by:
how to set input type label's value through javascript
0
7105
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,...
0
7132
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,...
0
7180
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
7341
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...
0
5439
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,...
0
3076
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...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
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...

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.