VBA: Toggle Button triple state property not working

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,384
Office Version
  1. 2016
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:

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,917
Changing the ToggleButton from False to Null does not trigger a Click event. Move your code into the Change event.
 

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,384
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,241
Messages
5,600,501
Members
414,383
Latest member
konmtu

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