PDA

View Full Version : Solved: CheckBox and a TextBox



themadtux
11-03-2010, 11:48 AM
I have a word document I'm wanting to have a couple activex elements within the document. I have checkboxes and textboxes. I want to only enable certain textboxes if the corresponding check boxes are checked. How do I go about doing this, I've never coded before so I am completely new to this.

For example I have a checkbox that's named ProjectName and a textbox named ProjectNameText. I want the ProjectNameText textbox to be disabled (not hidden or anything) until the user puts the check in the ProjectName checkbox. Once they put the check mark in, they can then fill out the Project Name.

How would I go about implementing this idea?

Thanks,

-Jason

Tinbendr
11-03-2010, 04:43 PM
Welcome to VBA Express!

If you've posted this question on another forum, please provide the link for that.

Could you u/l a sample document with the controls on it?

themadtux
11-04-2010, 06:28 AM
Welcome to VBA Express!

If you've posted this question on another forum, please provide the link for that.

Could you u/l a sample document with the controls on it?

Sorry about that.. no this wasn't posted from another site. I've attached the document. Hope this helps...

Thank you,

-Jason

Tinbendr
11-04-2010, 07:16 AM
When you enter design mode, you can select a control, right click and select View code. This should insert the default event into the ThisDocument module.

Select Document from the dropdown, then select, from the right dropdown, Open.

This is the basic instruction for getting the code started.

Now for the code.

On open, you want to set the Enabled property for each textbox you want disabled. So, for the Projectname textbox, we have this code.

Private Sub Document_Open()
'When the document is opened,
'set each of the textboxes you
'want disbled to Enabled=False.
With ThisDocument
.tbProjectName.Enabled = False
End With
End Sub


When a user checks the ProjectName Checkbox, this will trigger the Change event. During that event, we check the status of the property, and enable/disable the corresponding textbox.

Private Sub cbProject_Click()
'When the corresponding Checkbox is Changed,
'check the status of the checkbox
'and set the matching textbox accordingly.
With ThisDocument
If .cbProject Then
.tbProjectName.Enabled = True
Else
.tbProjectName.Enabled = False
End If
End With
End Sub

I've left most of the coding for homework :)

Post back if you have more questions.

David

themadtux
11-04-2010, 10:09 AM
When you enter design mode, you can select a control, right click and select View code. This should insert the default event into the ThisDocument module.

Select Document from the dropdown, then select, from the right dropdown, Open.

This is the basic instruction for getting the code started.

Now for the code.

On open, you want to set the Enabled property for each textbox you want disabled. So, for the Projectname textbox, we have this code.

...

Post back if you have more questions.

David

Thank you, that worked perfectly. Got all the textboxes that I wanted to have the checkboxes control all set. Time to figure out how to change the background of each box to a light grey till the checkbox is filled.

Again thank you muchly...

-Jason