Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Using a checkbox to activate/deactivate input option

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jacob - 19 Sep 2006 15:34 GMT
I have created a program using VBA and I am attempting to use a form
for my first time.  I want to have a checkbox that when checked allows
users to input additional items into the form.  by default I want the
box to be unchecked and those input boxes grayed out and disabled.
what is the best way to do this?  thanks.
Die_Another_Day - 19 Sep 2006 15:47 GMT
In the userform code area, use the userform_initialize sub with code
like this:
CheckBox1.Value = False
In the CheckBox1_Change Event use code like this:
TextBox1.Enabled = Not(CheckBox1.Value)
TextBox3.Enabled = Not(CheckBox1.Value)

HTH

Charles

> I have created a program using VBA and I am attempting to use a form
> for my first time.  I want to have a checkbox that when checked allows
> users to input additional items into the form.  by default I want the
> box to be unchecked and those input boxes grayed out and disabled.
> what is the best way to do this?  thanks.
Bob Phillips - 19 Sep 2006 15:50 GMT
add code like this to the form

Private Sub CheckBox1_Click()
   With Me
       If .CheckBox1.Value = True Then
           .TextBox1.Enabled = True
           .TextBox1.BackColor = &HFFFFFF
           .TextBox1.Enabled = True
           .TextBox2.BackColor = &HFFFFFF
       End If
   End With
End Sub

Private Sub UserForm_Initialize()
   With Me
       .CheckBox1.Value = False
       .TextBox1.Enabled = False
       .TextBox1.BackColor = &HC0C0C0
       .TextBox2.Enabled = False
       .TextBox2.BackColor = &HC0C0C0
   End With
End Sub

Signature

HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

> I have created a program using VBA and I am attempting to use a form
> for my first time.  I want to have a checkbox that when checked allows
> users to input additional items into the form.  by default I want the
> box to be unchecked and those input boxes grayed out and disabled.
> what is the best way to do this?  thanks.
Jacob - 19 Sep 2006 16:22 GMT
Thanks for the help. Chalres, I could not get yours to work.  Bob, I
added an "else" to get the cells to revert to the default of gray and
disabled after being checked and unchecked.  other than that, it
appears to be working perfectly.

thanks!

Private Sub CheckBoxShearEnv_Click()
   With Me
       If .CheckBoxShearEnv.Value = True Then
           .TextBoxIncrement.Enabled = True
           .TextBoxIncrement.BackColor = &HFFFFFF
           .TextBoxStepSize.Enabled = True
           .TextBoxStepSize.BackColor = &HFFFFFF

       Else
           .CheckBoxShearEnv.Value = False
           .TextBoxIncrement.Enabled = False
           .TextBoxIncrement.BackColor = &HC0C0C0
           .TextBoxStepSize.Enabled = False
           .TextBoxStepSize.BackColor = &HC0C0C0

       End If
   End With
End Sub

Private Sub UserForm1_Initialize()
   With Me
       .CheckBoxShearEnv.Value = False
       .TextBoxIncrement.Enabled = False
       .TextBoxIncrement.BackColor = &HC0C0C0
       .TextBoxStepSize.Enabled = False
       .TextBoxStepSize.BackColor = &HC0C0C0
   End With
End Sub

> add code like this to the form
>
[quoted text clipped - 31 lines]
> > box to be unchecked and those input boxes grayed out and disabled.
> > what is the best way to do this?  thanks.
Bob Phillips - 19 Sep 2006 22:59 GMT
I wondered if you would want them to revert <g>

Signature

HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

> Thanks for the help. Chalres, I could not get yours to work.  Bob, I
> added an "else" to get the cells to revert to the default of gray and
[quoted text clipped - 67 lines]
> > > box to be unchecked and those input boxes grayed out and disabled.
> > > what is the best way to do this?  thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.