VBA: Toggle Button triple state property not working

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,585
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Private Sub ToggleButton1_Click()
    If IsNull(Me.ToggleButton1.Value) Then
        Me.ToggleButton1.Caption = "Pending"
        Me.ToggleButton1.BackColor = Me.BackColor
    ElseIf ToggleButton1.Value = True Then
        Me.ToggleButton1.Caption = "Done"
        Me.ToggleButton1.BackColor = rgbGreen
    ElseIf Me.ToggleButton1.Value = False Then
        Me.ToggleButton1.Caption = "Waived"
        Me.ToggleButton1.BackColor = rgbMediumPurple
    End If
End Sub

VBA Code:
Private Sub UserForm_Initialize()
Me.ToggleButton1.Value = Null
End Sub

The toggle button's caption is not getting reflected as "Pending" when the value is "Null".
When I launch the form the togglebutton value is Null and I see the caption as "pending" as shown in below picture.
Like this: (But this same caption is not coming again once I click on the toggle button)
1587223100775.png


then when I click the button,
the button turns green and caption becomes "Done" -- 1st button in below picture.
On clicking again,
the button turns purple and caption becomes "Waived" -- 2nd button in below picture.
On clicking again,
neither the color nor the caption changes. Just the color gets dim (which I believe is for null value) -- 3rd button in below picture

If I keep pressing the toggle button, it keeps toggling between the below given 3 figures.

How can I get the toggle button to look as above i.e. caption : Pending & backcolor : me.backcolor


1587223138620.png

Any help is highly appreciated.
 
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Changing the ToggleButton from False to Null does not trigger a Click event. Move your code into the Change event.
 
Upvote 0
Changing the ToggleButton from False to Null does not trigger a Click event. Move your code into the Change event.
You are an angel.
Thank you so much.. I was trying to figure this out for such a long time.
 
Upvote 0
Rather than putting the OP code in the Click event, as it is, just put the exact same code in the Change event.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

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