Toggle button code- unclicking the toggle button

shornco

Board Regular
Joined
Feb 4, 2003
Messages
91
I'm having trouble understanding how to get actions done when a toggle button is unclicked. In my user form, the toggle button's purpose is to enable or unenable a text box. In addition to enabling, I'm also toggling the text box's back color and the forecolor of the text box label. I have been successful enabling and unenabling the text box with this code:

MyTextBox.Enabled = MyToggle.Value

For the forecolor and backcolor, I'm trying this and it's not doing any action when I unclick:

With MyToggle.Value = True
MyTextBox.BackColor = ColorConstants.vbWhite
MyLabel.ForeColor = ColorConstants.vbBlack
End With
With MyToggle.Value = True
MyTextBox.BackColor = 15
MyLabel.ForeColor = 15
End With

Basically, I'm trying to get the code for MyToggle.Value = False

Thank you.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

rjp

Board Regular
Joined
Jan 5, 2006
Messages
148
Hope I've understood the question, try this:

Code:
If MyToggle.Value = True Then
    MyTextBox.BackColor = ColorConstants.vbWhite
    MyLabel.ForeColor = ColorConstants.vbBlack
Else
    MyTextBox.BackColor = 15
    MyLabel.ForeColor = 15
End If
 

Forum statistics

Threads
1,136,613
Messages
5,676,813
Members
419,652
Latest member
jjakub33

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top