VBA: Toggle Button triple state property not working

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,383
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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,804
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,383
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,113,903
Messages
5,544,974
Members
410,647
Latest member
LegenDSlayeR
Top