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

Active, Inactive textboxes

P: 29
I have a form needs to be filled out. A lot of the questions are a yes/no question. When they pick yes I want some other textboxes to be active, and when they pick no I want the textboxes to be inactive. Example - A question could be: Do you have siblings. If you check yes, then other line would appear to say “How many” (other textboxes are active)? If you say no, then it skips to the next question (other textboxes are inactive - grayed out).
How do I do this? If it includes coding, can I get help with the coding?
Aug 6 '08 #1
Share this Question
Share on Google+
20 Replies


NeoPa
Expert Mod 15k+
P: 31,186
It does include coding, but at what I would say is a fairly basic level.

Say you have a TextBox control [txtQ1] which expects either "Y" or "N". When the response "Y" is entered you want another TextBox [txtA1] to be enabled for input, but when the response "N" is entered you want TextBox [txtA1] to be disabled for input.

The following code could then be used to cause this to happen. This is called an Event Procedure and in this case it handles the AfterUpdate event for the [txtQ1] control.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtQ1_AfterUpdate()
  2.     Me.txtA1.Enabled = (Me.txtQ1 = "Y")
  3. End Sub
Aug 6 '08 #2

P: 29
It does include coding, but at what I would say is a fairly basic level.

Say you have a TextBox control [txtQ1] which expects either "Y" or "N". When the response "Y" is entered you want another TextBox [txtA1] to be enabled for input, but when the response "N" is entered you want TextBox [txtA1] to be disabled for input.

The following code could then be used to cause this to happen. This is called an Event Procedure and in this case it handles the AfterUpdate event for the [txtQ1] control.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtQ1_AfterUpdate()
  2.     Me.txtA1.Enabled = (Me.txtQ1 = "Y")
  3. End Sub


It does work but if I pick one record that is no, all textboxes going forward locked/grayed out. Can I have a code to reset on every new record
Aug 7 '08 #3

NeoPa
Expert Mod 15k+
P: 31,186
It does work but if I pick one record that is no, all textboxes going forward locked/grayed out. Can I have a code to reset on every new record
I'm sorry I don't understand you :S

This isn't a continuous form is it?
Aug 7 '08 #4

P: 29
I'm sorry I don't understand you :S

This isn't a continuous form is it?
Let's hope this will clear it up:
Example: First question - Do you have any any siblings?
Second question - How many
I want the "How Many" question to be Disabled/Inactive until the first question is picked(yes).
Here is my actual code so far:
Expand|Select|Wrap|Line Numbers
  1. Sub txtIs_AfterUpdate() 
  2.   Me.txtApplication.Enabled = Me.txtIs 
  3. End Sub
What do I need in addition to the code to make this work? Thank you for your help.
Aug 7 '08 #5

NeoPa
Expert Mod 15k+
P: 31,186
I think you copied the code down wrong.

Assuming the fields you've used match the correct controls, you need :
Expand|Select|Wrap|Line Numbers
  1. Sub txtIs_AfterUpdate() 
  2.   Me.txtApplication.Enabled = (Me.txtIs = "Y")
  3. End Sub
Aug 7 '08 #6

NeoPa
Expert Mod 15k+
P: 31,186
...
Expand|Select|Wrap|Line Numbers
  1. Sub txtIs_AfterUpdate() 
  2.   Me.txtApplication.Enabled = (Me.txtIs = "Y")
  3. End Sub
What this is saying is :
  • Every time the operator makes a selection in Me.txtIs
  • First determine if Me.txtIs is "Y" or not (in the parentheses).
  • Assign this boolean (True/False) result to Me.txtApplication.Enabled.
Does that make better sense now?
Aug 7 '08 #7

P: 29
What this is saying is :
  • Every time the operator makes a selection in Me.txtIs
  • First determine if Me.txtIs is "Y" or not (in the parentheses).
  • Assign this boolean (True/False) result to Me.txtApplication.Enabled.
Does that make better sense now?
After applying this code, when I check the box - the textbox that I want to be enabaled is actually disabled (it was enable to start out which I want it disable until I check the box). Thank you for your help and hope you can still help me on this.
Aug 7 '08 #8

NeoPa
Expert Mod 15k+
P: 31,186
You will probably need to provide some more info then. I'm running on air here nearly.

What type of control is txtIs (a TextBox I would guess)?
What's the exact question they are expected to answer?
Is the user entering "Y"? Maybe they enter "y"? Or "Yes" or something.

In any case, I think the code should probably change to the following so that we needn't care how they enter it :
Expand|Select|Wrap|Line Numbers
  1. Sub txtIs_AfterUpdate()
  2.   Me.txtApplication.Enabled = (UCase(Me.txtIs) = "Y")
  3. End Sub
Aug 7 '08 #9

P: 29
You will probably need to provide some more info then. I'm running on air here nearly.

What type of control is txtIs (a TextBox I would guess)?
What type of control is txtIs (a TextBox I would guess)?
Is the user entering "Y"? Maybe they enter "y"? Or "Yes" or something.

In any case, I think the code should probably change to the following so that we needn't care how they enter it :
Expand|Select|Wrap|Line Numbers
  1. Sub txtIs_AfterUpdate()
  2.   Me.txtApplication.Enabled = (UCase(Me.txtIs) = "Y")
  3. End Sub
To help you help me, here are the answers to you question:
What type of control is txtIs (a TextBox I would guess)? - Data type is Yes/No (so on the form all I get is a box to check)

What type of control is txtIs (a TextBox I would guess)? - I'm assuming that if a user checks the box this would be a "yes".

So txtIs is the checkbox for Yes/No and txtApplication is the next question that should only be active/enable if a user checks the txtIs checkbox. Also, I want txtApplication to be Inactive/Disabled when the user opens the form, right now it's active.
Aug 8 '08 #10

NeoPa
Expert Mod 15k+
P: 31,186
Ah, it seems you are not yet aware WHY we preceed the name with things like "txt", "cbo", "bln" etc.

txtIs indicates that the control is a TextBox. For a Yes/No field you should use "bln" instead. Thus the control should be named [blnIs].

This explains why the code didn't work. The code was directed at a TextBox control.
...
What type of control is txtIs (a TextBox I would guess)? - I'm assuming that if a user checks the box this would be a "yes".
...
No! Most emphatically not.
Most can only return values of True or False (NB. Not strings "True" and "False", but boolean values which have numerical equivalents of -1 & 0 respectively).
...
Also, I want txtApplication to be Inactive/Disabled when the user opens the form, right now it's active.
...
I thought I'd already said to set this to Enabled=No in the design, but I checked the thread and it's not there anywhere - Ooops. That's what you need to do anyway.

Try this new code for your boolean (Yes/No) field (NB. The control should be renamed first to indicate the type) :
Expand|Select|Wrap|Line Numbers
  1. Sub blnIs_AfterUpdate()
  2.   Me.txtApplication.Enabled = Me.blnIs
  3. End Sub
Aug 8 '08 #11

P: 29
Thank very very much. It works.
Aug 11 '08 #12

NeoPa
Expert Mod 15k+
P: 31,186
Very pleased to hear it and you're welcome :)
Aug 11 '08 #13

P: 29
Very pleased to hear it and you're welcome :)
Now I got another question related to this. The code that you gave me works but if I check yes (blnIS) for the active record that I'm on and then when I'm finished filling out the form and move on to the next form - the txtApplication is already active. It's suppose to be inactive/deactivated until the user checks yes (checks the blnIS checkbox).

The code that I'm using is:
Expand|Select|Wrap|Line Numbers
  1. Sub blnIs_AfterUpdate()
  2.   Me.txtApplication.Enabled = Me.blnIS
  3. End Sub
What additional code do I need.
Aug 12 '08 #14

NeoPa
Expert Mod 15k+
P: 31,186
You need similar code in your Form_OnActive() event procedure.
Aug 12 '08 #15

P: 29
You need similar code in your Form_OnActive() event procedure.
Not following you on your statement there. Can you go more into detail.
Aug 12 '08 #16

NeoPa
Expert Mod 15k+
P: 31,186
My bad! I meant OnCurrent not OnActive. Was rushing home at the time ;)

Something like the following :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me.txtApplication.Enabled = Me.blnIS
  3. End Sub
Obviously this would need to be handled for each such connected pair of controls on the form.

Is that a little clearer?
Aug 12 '08 #17

P: 29
My bad! I meant OnCurrent not OnActive. Was rushing home at the time ;)

Something like the following :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me.txtApplication.Enabled = Me.blnIS
  3. End Sub
Obviously this would need to be handled for each such connected pair of controls on the form.

Is that a little clearer?
Sorry, but I don't know where to find "OnCurrent" on the form. Can you please tell me how or where to go.
Aug 12 '08 #18

NeoPa
Expert Mod 15k+
P: 31,186
Sure.
  1. Open the form in Design View.
  2. Right-click in an unused area of the grid (Not on any part of the form itself).
  3. Select Properties (if they are not already visible of course).
  4. In the Properties pane select either the Event or All tabs.
  5. Navigate to On Current.
  6. From the drop-down select [Event Procedure].
  7. Click on ellipsis button (...) to the right.
Bingo!
Aug 12 '08 #19

P: 29
Sure.
  1. Open the form in Design View.
  2. Right-click in an unused area of the grid (Not on any part of the form itself).
  3. Select Properties (if they are not already visible of course).
  4. In the Properties pane select either the Event or All tabs.
  5. Navigate to On Current.
  6. From the drop-down select [Event Procedure].
  7. Click on ellipsis button (...) to the right.
Bingo!
Got it. I click on the very little square on the top left side in Design View, went to properties and did what you said. IT WORKS WONDERFULLY. Thank you very much.
Aug 12 '08 #20

NeoPa
Expert Mod 15k+
P: 31,186
"Oh ye of little faith!"

You sound surprised :D

Seriously, it's a pleasure to help.
Aug 12 '08 #21

Post your reply

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