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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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
Back
Top