Link to home
Start Free TrialLog in
Avatar of bfuchs
bfuchsFlag for United States of America

asked on

How to display X in a check box control?

Hi Experts,

Looking for a way to display X inside a check box in case user selects no, that is instead of being just blank.

I'm also open for alternative tricks that can mimic this behavior.

Thanks
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

You don't need tricks, just put selected="selected" in the checkbox code.
http://www.w3schools.com/tags/att_selected.asp
This is a Check Box in an Access Database ...
Well, you can:

1. set the default value of the control to -1, or
2. set the default value of the field in the table where the data comes from = -1
3. or use the Form_Current event to set that value to -1 if on a new record, like:
Private Sub Form_Current

    if me.newRecord then me.chk_ControlName = true

End Sub

Open in new window

I'm sure there are other methods, but these are the ones I commonly use.
Checkboxes have three states.  Checked, unchecked (empty), null (darker blob).  That's it.  There are no tricks.  This is an Access control and we cannot change how it operates.  If you want a positive yes/no, use a combo.  It won't be a graphic but you can force it to show True/False, Yes/No or whatever your options are.  A third possibility is to use an option group.  These cannot be used on forms in data sheet view and obviously won't render in queries or tables.  Your option group can show two boxes and only one of them can be checked.
<<Looking for a way to display X inside a check box in case user selects no, that is instead of being just blank.>>

Use a text control along with the  Wingdings font, and then use the format() function for the true/false using:

[Alt]+ Key pad 0168 for a blank square
[Alt]+ Key pad 0168 for an "X"
[Alt] + Keypad 0252 for a check mark
[Alt]+ Key pad 0253 for an X in a square
[Alt]+ Key pad 0255 for a check mark in a square

Jim.
SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
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
Ben

Are you looking for an X for no and a checkmark for yes?
I think that is what you are asking.

As @JDettman notes, that takes some legerdemain.
Providing it is not on a continuous form you can have a transparent textbox over the checkbox control with an x in it.  It is visible if the value is false, and not visible if the value is true.
The textbox can have a click event to change the underlying checkbox.
Jim and Nick have both provided options that could solve your problem if you can use VBA.

Personally, I don't like using the standard check box with a graphic "X" box overlay as both have suggested.  Unless you see both variations on the same page, I believe it will be confusing.  Even if you can see both options, it will be confusing unless you know definitively that for Sam's record the check means "Active" and the "x" means "Inactive".  Then you can use Sam's record to decode the rest.  When filling out a form by hand or with a typewriter, people use an "X" for "true" so your idea of using the "X" for "false" and the check for "true" is likely to cause more confusion than it saves.  If you properly name the checkbox, people will understand its meaning and will will know that blank is the opposite of checked.

There are certain interface elements that have become "standard" during the last century and I would not mess with them.
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 am not big on it either for forms, make no mistake @PatHartman.
If the users come to expect it, then you have to do it everywhere

Reports are a different story
Checkboxes don't scale and in a report an unchecked box doesn't necessarily suggest 'badness'
A red X certainly does.
Look at the three elements circled.  The x does have its place in UIUser generated image
> [Alt]+ Key pad 0168 for an "X"

That should be Alt-0251. Here's a screenshot of a Word file I did a while ago:

User generated image
Regards, Joe
On a report, you can easily use an option group with three boxes.  checkbox 1 for yes,  checkbox 2 for no and checkbox 3 for unspecified.  But I have no objection to something red and obviously not a "true" checkmark to indicate something is missing.   User generated image
Avatar of bfuchs

ASKER

Wow received such nice response!

(I wish would have this in all my posts-:)

Will have to do some testing in order to finalize..

@Jim,
and then use the format() function for the true/false using:

[Alt]+ Key pad 0168 for a blank square
Not sure I got it, what exactly do I have in the control source of that text box?
I will have 3 controls, a checkbox, a text box and a command button?


@Nick,
It is visible if the value is false, and not visible if the value is true.
The textbox can have a click event
Tried following it but got stuck, how can an invisible control fire an event?

Can you upload a demo?


@Ray,
How can I add option for gray when its not selected?

@Pat,
You have a point, and I usually use normal check boxes behavior, however my users started complaining that they often get confused between false and null (not selected), and they were the ones requesting the X, I tried convincing them to use a combo as you mentioned but they're insisted.., so I guess will try this, and when they complain again its confusing I will change back..

Thanks,
Ben
Avatar of bfuchs

ASKER

BTW,

(while I have you all here..:)

When first typing my response, I switched programs & suddenly booms everything is gone!

This is happening to me very frequently lately.

See attached.

Does anyone knows the reason for it?

Thanks,
Ben
untitled.png
Can you upload a demo?
ok fine

Does anyone knows the reason for it?
<grin> Chrome </grin>

I  haven't had problems in IE 11
checkbox.mdb
Avatar of bfuchs

ASKER

@Nick,

Thanks for uploading,

Just have two issues.
1- the mouse loses its pointy look and seems like typing into a text box.
2- there are only two states, and how do I deal with null value?

Chrome
I always used it, is this something new that EE is not compatible with it?

Thanks,
Ben
"2- there are only two states, and how do I deal with null value?"
if you want a true Tri-State check box ... you have to do two things.

1.  Change the Check Box to Tri-State
2. You must you an Integer Data Type instead of a Yes/No Data Type, because and  Integer Data Type can be set to Null ... and Yes/No cannot

In the Tri-State scenario ... you will see the following
If the Check box has never been 'checked' ... it will sort of grayed out.
If the Check box is checked, then unchecked .... it will be a clear (white?) background.
If the Check box is checked, then you will see the check mark.

The Tri-State mode is very handy when .... you want the user to make a Yes OR No selection, ie ... this is a required field.  So, you can test for Null in say the Form BeforeUpdate event, and prompt the user to make a Yes or No selection.

Note the value in the Integer data type will be either Null, 0 (False - unchecked) or -1 (True - checked).
Consequently you have to take this into account in queries, etc.
Avatar of bfuchs

ASKER

@Joe,

I was referring to Nick's demo solution which is setting the textbox value by following

Public Function IsItVisible(TheBoolean) As String
If TheBoolean = True Then
    IsItVisible = ""
Else
    IsItVisible = "x"
End If
End Function

Open in new window


Thanks,
Ben
Well, consider it a lesson in case you do want a real Tri-State check box lol.

You know ... I get what you want to do ... show an X to indicate NOT check, show a Check Mark to indicate Checked ... but  ... overall ... kind of a hassle ... but I get it.
Just have two issues.
 1- the mouse loses its pointy look and seems like typing into a text box.
 2- there are only two states, and how do I deal with null value?


It is legerdemain.
You ARE actually clicking into a textbox.
(That's why @JDettman's solution involved transparent command buttons, so you wouldn't have the mouse change)
There is a Click() event for that textbox.
It changes the value of the checkbox, and tosses the focus away to a control just 0.0007 wide.
It isn't perfect, not by a long shot, but then nothing is when you are cobbling together UI for whiney end-users ;)

Null Booleans are a great evil.  I suggest very highly that you do NOT permit them.
Have the field with a default.
The way Boolean nulls propogate and fail to display can drive you nuts.
When you open a table with Boolean values, you see 0 or -1, and that's it
Access has no way to display a null in a Boolean field.
Then you do totals work.  And your total 0's + total -1's don't add up to your recordcount.
So you do a Count([theField]) and get THREE rows one -1 row and two 0 rows, one of the two of which is your nulls -- BUT WHICH!!!!

Very evil.  Don't go there.

If you must, then you will need to alter my code for a three-part merry go round
One click goes from true to false,  then next from false to null, the third from null to true.
And you must decide what value will be in the textbox when it is null.

BUT DON'T GO THERE.
REALLY.
JUST DON'T.
"Null Booleans are a great evil."
A Boolean Data Type cannot be Null.
Avatar of bfuchs

ASKER

@Joe, @Nick,

I am absolutely ok dealing with an int instead of a boolean, and in fact this is how I use it most of the time as I dont see how to handle nulls otherwise.

The only issue here is the X in the check box.
It isn't perfect, not by a long shot, but then nothing is when you are cobbling together UI for whiney end-users ;)
you right, its not always possible to deliver what users demand..however we still need to give it a try..I feel we are very close to getting it solved.

Perhaps you can help me figure out how to handle it in Ray's example, as there I only have to solve the 3 state issue.

Thanks,
Ben
@mx my old friend, a bit datatype can certainly be null, and you can link a SQL server table into Access and have your nulls and curse at them, too.

Been there.  Done that.
Thinner hair and greyer.
An Access local table creation doesn't APPEAR to have nulls.
If you FAIL to specify a default and upsize that baby to SQL Server, your nulls will be there, though.
Been there, done that too.

Evil.  Very evil.
Avatar of bfuchs

ASKER

FYI- Ray's code is the following

Private Sub LabelLargeCheck_Click()
'Stop
[chkX] = Not [chkX]
If Nz(chkX, 0) Then
    LabelLargeCheck.Caption = Chr(254)
    Else
    LabelLargeCheck.Caption = Chr(253)
End If
End Sub

Open in new window


Thanks,
Ben
" a bit datatype"
A Yes/No Data Type in Access cannot be set to Null ... try it.
The default is False, not Null.
An Integer Data Type (et al) can be set to Null.

"Perhaps you can help me figure out how to handle it in Ray's example,"

Rey really needs to do that ... to keep everything on the up and up :-)
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
@mx
In a local table you are absolutely right.
But A LOT more than local tables can be used in Access.
And Access maps a SQL Server bit datatype to Boolean -- but you can set bit datatypes to null in any number of ways.

And then no, Access doesn't treat them as false.
It's very evil.
Try it sometime.

Create a table in SQL Server with an identity field and a bit field and a textfield
Link it in Access
Happily add records using only the textfield
What ACCESS shows in the bit field is false -- but what is really there is null.
Change a few 'false' to true in Access.
Change a few true to false in Access.

In SQL Server, you'll have a fine mess of 1,0, and nulls.
And do a Count() in Access and you'll see the footprints.
Very Evil.
Learned my lesson the hard way
'Always give Access Boolean fields a default value--when you upsize you'll be glad you did'
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
Avatar of bfuchs

ASKER

@Nick,

Ok I just got a chance to test your latest and that solved the 3 state issue.

Now in regards to the mouse issue, perhaps we can use what Jim mentioned above
you can use a transparent command button over the top of the text control if you want the user to be able to change the value
Meaning that should be placed on top of both controls, and used to change the values.

My question would be, how do you set a command button as transparent, in the version we use (2003) this isn't an option?

Thanks,
Ben
Avatar of bfuchs

ASKER

Disregard my last comment.
Avatar of bfuchs

ASKER

Would really like to thank all participants!

Yes, when there is a will there is a way..

Ben