Activate Text Box when selecting a Check Box?

YNWA

Registered User.
Local time
Today, 21:25
Joined
Jun 2, 2009
Messages
905
Hi, I have a form with a number of check boxes in it.

It is used for a user to select patient treatments, so I have things like insulin, anti-biotics etc... and then a check box called "Other".

Is there a way to create a check box that when checked will activate a text box to show on the form, for a user to enter some text on what that "Other" treament could be?



Thanks
Will
 
If you use the OnClick event of the check box and test for True/False and set the textbox to be enabled/disabled according to the response.

David
 
Hi YNWA,

Here is what you need to do:
- set default value for check box to 0
- disable the text box (enabled: No)
- right-click check box and choose Build Event... and then Code Builder
- in VBA window insert something like this (change values to match your check box and text box):

Private Sub Check3_Click()
If Me!Check3.Value = True Then
Me!Text5.Enabled = True
Else
Me!Text5.Enabled = False
End If
End Sub

Instead of Enabled property, you can also use Visible or Locked, but I guess Enabled is more common.

Best regards,
BrankoG
 
The OP actually said he wanted the textbox to "show" if the checkbox was ticked. Something like this:

Code:
Private Sub Other_AfterUpdate()
 If Me.Other = -1 Then
  Me.OtherTreatment.Visible = True
 Else
  Me.OtherTreatment.Visible = False
  Me.OtherTreatment.Value = Null
 End If
End Sub
Code:
Private Sub Form_Current()
 If Me.Other = -1 Then
  Me.OtherTreatment.Visible = True
 Else
  Me.OtherTreatment.Visible = False
  Me.OtherTreatment.Value = Null
 End If
End Sub

The Else clause is needed in case the user makes a mistake or changes his/her mind about it being checked.

Me.OtherTreatment.Value = Null

also removes anything entered in the texbox if the user unticks the checkbox.
 
Thanks guys, will give this a go now. Superstars the lot of you. Cheers

ps. just did it and works a treat.

But...

How do I store the comments in my table? I have a field for Other but its a Yes/No field for the check box, can I change this to text box and this will incert comments?
 
Ah just clicked to the next record in the form and the previous comment is there.

Also when I start the form using missinglinq code, the text box is there visable and usable. Only when I click Other and declick Other does it disappear?

I want to store the comments in the Other field in my table, I also want to flick from record to record and the Other box with remain empty/visable depending on whether info is in it or not?
 
You have to create a new field in your underlying table, then set the ControlSource for you r textbox to this field. Once you do this, all of the problems you've cited will disappear.
 
I have a problem with this...

When I start the form, I have the text box disabled. So when you click on a new record, the Other box is shaded out, only when you click the Other checkbox will it activate the text box.

However once entered, when I click add visit to add another visit for the saem record, the Other box is unchecked (as it should be) however the text box is activated.

The code I have is

Private Sub Other_Click()
If Me!Other.Value = False Then
Me!Text44.Enabled = False
Else
Me!Text44.Enabled = True
End If
End Sub

I swaped the true and falses around so its not enabled until you click the other box. I also changed the "enabled" property of the text box to NO.

Anyone help me with getting the text box to stay shaded out until a user clicks "Other"? Works when you start the form, but doesnt work when you add new records after using the text box.

Also when you scroll through previous entires, those who have Other checked and text in the text box are shaded out, you need to uncheck and recheck in order to enter any other info.?
 
The OP actually said he wanted the textbox to "show" if the checkbox was ticked. Something like this:

Code:
Private Sub Other_AfterUpdate()
 If Me.Other = -1 Then
  Me.OtherTreatment.Visible = True
 Else
  Me.OtherTreatment.Visible = False
  Me.OtherTreatment.Value = Null
 End If
End Sub
Code:
Private Sub Form_Current()
 If Me.Other = -1 Then
  Me.OtherTreatment.Visible = True
 Else
  Me.OtherTreatment.Visible = False
  Me.OtherTreatment.Value = Null
 End If
End Sub

The Else clause is needed in case the user makes a mistake or changes his/her mind about it being checked.

Me.OtherTreatment.Value = Null

also removes anything entered in the texbox if the user unticks the checkbox.

Hi mate, I am using this code you gave me.

However a slight problem.

When I load the form, the Other Details text box is not there which is good. When I click the Other checkbox, the Other Details text box does not appear, not good.

THen if I go to the next record and then go back to previous record, the Other Details check box is visable. If I uncheck the Other checkbox, the Other Details text box does not disable/disappear, however once I go to next record and back again, the Other Details text box has disappeared.

How do I get this to update when I check or uncheck the Other checkbox?
 
SOrted it, the After Update event although I went through code builder, did not save into the after update properties of check box. my bad.
 

Users who are viewing this thread

Back
Top Bottom