Tristate test not working

Sinbad

Board Regular
Joined
Apr 18, 2012
Messages
224
Hi all, have a checkbox and need to test for its 3 states. true, false and null.

true and false are working fine, null just wil not work. any suggestions.

simple userform with a single checkbox and the following code attached to it for testing.

Code:
Private Sub CheckBox1_Click()
    If IsNull(CheckBox1.Value) Then
        CheckBox1.Caption = "Value is Null"
    ElseIf CheckBox1.Value = False Then
        CheckBox1.Caption = "Value is False"
    ElseIf CheckBox1.Value = True Then
        CheckBox1.Caption = "Value is True"
    End If

End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
ok, that way works. but means i have to have 2 subs. one for the click event and one for the change event. Any way to combine both into one ?
 
Upvote 0
Why do you need the click event? If you click it, it changes.
 
Upvote 0
I have three options i want to take care of with one button.

as follows..

the check box is labeled "Courier or local"
If true, hardware has to be sent away by courier.
if false, hardware is delivered localy
if null, user still needs to be determined if hardware stays local or has to be sent away. (see i can´t use the empty state as this means send it locally... the third greyed state is just perfect)

So the third state is used to prompt the user to take a decision. It does not have to be today, tomorrow etc.. just a visulal reminder that this specific item has no shipping attached to it yet.

So I want to use the three states to enter text into a cell, if null --> change its background and put the text ie "undetermined" into it. if it is true the cell will contain "courier" and transparent and if false the cell will have "Local shipment only" and yellow as background

if i use my code, i don´t seem to be able to get to the third state.-- NULL with a combination of yours and mine, i can get all three states but means i have 2 subs ??
the click event and one for the change event

Or how do i combine both ? that is the question...
 
Last edited:
Upvote 0
You've lost me.

Change the word Click to Change and the rest of your code works fine.

I'd use three option buttons instead of a checkbox.
 
Upvote 0
Brilliant.. working. Thank you.

I´d like to use three buttons as well, but don´t have the space on the form to do that. Maybe we´ll re-design it someday, but for now I got what I needed. code as follows for those that want to do the same..

Code:
Private Sub CheckBox1_Change()
    If CheckBox1.Value = True Then
        CheckBox1.Caption = "Value is True"
        Label1.Caption = CheckBox1.Value
    ElseIf CheckBox1.Value = False Then
        CheckBox1.Caption = "Value is False"
        Label1.Caption = CheckBox1.Value
    Else 
        CheckBox1.Caption = "Value is Null"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,206,971
Messages
6,075,925
Members
446,170
Latest member
zzzz02

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