Link to home
Start Free TrialLog in
Avatar of Milewskp
MilewskpFlag for Canada

asked on

How to make a null-valued checkbox appear white instead of gray

When the control source of a checkbox is a field on the arrow end of an outer join between two tables, it will appear gray when its value is null, even when the checkbox's Triple State property = No.

How can I make the checkbox appear white when the value is Null?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

That is the point of it being gray ... which means that it has never been check or unchecked, either manually or via vba code.

Why is this a problem ?

mx
SOLUTION
Avatar of danishani
danishani
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another plan of attack is to tweak your query.
Have it return an additional calculated column WhateverDisplays:Nz([Whatever],0)
Put WhateverDisplays directly on top of the other checkbox
Make your bound control invisible when it is null, and add an GotFocus event to the WhateverDisplays control to change the field from Null to True.

But I am with mx
Grey null boxes serve a purpose, they tell you that you have never tried to set the value.
White is false
Checked is true.

Unless you have some heavy reason to override that default logic, I wouldn't.
It DOES tell you something; why hide it?
Is this the same "Calculated" Yes/No Field as you have here?:
https://www.experts-exchange.com/questions/27041921/Update-Delay-when-user-clicks-Checkbox.html


<How can I make the checkbox appear white when the value is Null?>
Why?
Checkboxes are normally associated with Boolean fields.

"White"=Un-Checked=No=0=False

I don't know of any interface where an empty ("White") boolean checkbox means null...

So I, like the previous experts am a bit confused by this request...

As always, please include the "Why" behind your request, in case there is an alternate approach...


JeffCoachman

Avatar of Milewskp

ASKER

Hi Folks,
The checkbox is used to indicate that the item described by that record has been selected. There are therefore only two states from teh user's point of view: selected or not, and they were confused (and complaining) about the Null. The Null is just an artifact due to the two table structure I'm using as the basis of the recordsource.

Hi danish,
<You can set the default value on 0>
This won't help in my case, since the null is due to a non-existant record in the table on the arrow side of the outer join.
Your link looks interesting; I'll have a closer look.

Hi Nick,
<Make your bound control invisible when it is null, and add an GotFocus event to the WhateverDisplays control to change the field from Null to True.>
Interseting idea, I'll paly with that and let you know how it goes.

Hi Jeff,
<Is this the same "Calculated" Yes/No Field as you have here?>
Yes.

<There are therefore only two states from teh user's point of view: selected or not, and they were confused (and complaining) about the Null. The Null is just an artifact due to the two table structure I'm using as the basis of the recordsource.>
Then there are really three states, True, False, and the "Confusing" Null...

If this is the case (and this is just my opinion here...because I don't know thw nature of the query) I would stay away from using a Boolean Display control (CheckBox, Option Button) to display this data.

(I was never crazy about the Tri-State Property because it seemed to muddy the waters as far as how a boolean field could be displayed...)

If it were me, I would use a textbox to display this data.
Have some simple If-Then-Else logic:
If YourQueryCalc=True Then
    YourTextBox="Selected"
ElseIF YourQueryCalc=False Then
    YourTextBox="Not Selected"
ElseIf Isnull(YourQueryCalc) then
    YourTextBox=""
End if

Or, as was previously mentioned, use a "Fake" control or conditional formatting to set some visible indicator of the Field's contents.


JeffCoachman
"How can I make the checkbox appear white when the value is Null?"
The answer to this question is this:
IF ... you are going to use the Check box control, then you can't.  If you want it to be white, then either set the Default Value at the Table level to False, or set the check box value to False when the Form opens during Load.

These are your options ... IF ... you use the check box control.
"There are therefore only two states from teh user's point of view: selected or not,"

If that is the case, then I don't see the confusion.  Set the value to False when the Form loads ... to get the White check box.

mx
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'll accept Nick's solution, since it answers the question (thanks Nick), but the implementation I've decided on is to throw out checkbox controls altogether when dealing with tristate situations. (Partial points for danish's allen browne link - excellent discussion there.)

I will go one step beyond browne and use text fields and text controls using the values "Y", "N" and Null (rather than -1, 0 , Null). Sure it's not so elegant when interrogating the value of the control (must use 'If MyControl="Y" then...' rather than 'If MyControl then   ' ), but it's easier for the users to understand, there are no gray-white issues, no weird delays
(see https://www.experts-exchange.com/questions/27041921/Update-Delay-when-user-clicks-Checkbox.html.),
and no unnecessary combo box drop down lists and arrows (ala browne).

I've spend most of the day trying to come up with a more elegant solution, but there seems to be a down side to each one I've tried, so Y, N, Null is the solution for me.