By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,705 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,705 IT Pros & Developers. It's quick & easy.

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

P: 1
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
Share this Question
Share on Google+
7 Replies


ADezii
Expert 5K+
P: 8,669
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
Expert 2.5K+
P: 3,532
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
Expert 2.5K+
P: 3,532
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
Expert 5K+
P: 8,669
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
Expert Mod 15k+
P: 31,656
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
Expert 5K+
P: 8,669
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
Expert Mod 15k+
P: 31,656
Forget 'Almost' ADezii ;)
Dec 17 '07 #8

Post your reply

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