use a textbox as a resizeable and colourful checkbox (1 Viewer)

Status
Not open for further replies.

CJ_London

Super Moderator
Staff member
Local time
Today, 19:47
Joined
Feb 19, 2013
Messages
16,553
For whatever reason, checkbox controls cannot be resized. This suggestion addresses that issue and also enables the use of colour.



To create, put the following in the format property of a textbox and set the control source to a boolean value

1. set format property - [[Blue]\R;[Green]\R;[Red]\S;©
2. set font - wingdings
3. set font size as required - suggest 16 if normal font size is ll
4. set border to transparent
5. set enabled=no
6. set locked=yes
7. set tab stop to No

note enabled=no and locked=no will 'grey out' the control so colours are removed.

sometimes you might want null or false to be represented by an empty square box in which case change the S or © in the format string to £ (chr163)

I've included a 'blue tick' because any number other than 0 is 'true' and you might want to differentiate between -1 and another value such as a count.

if the underlying field is required to be updateable then set enabled=true and in the onclick event put

Code:
if not mycontrol.locked then mycontrol=not nz(mycontrol,false)
locked only prevents users from manually entering data, not changes made by clicking

However this creates a presentational issue as the control now has the focus and will be trying to display the actual underlying value, so we need to move the focus elsewhere. You may have a control you can move it to. If not, create an unbound textbox called say 'txtFocus' and set top, left, width and height properties to 0. Then modify the control click event to

Code:
txtFocus.setfocus
if not mycontrol.locked then mycontrol=not nz(mycontrol,false)

and in the control doubleclick event put

txtfocus.setfocus

to prevent the cursor staying on the control


Finally, you may have an issue that the control receives the focus when the form opens. If so, change the tab order so another control receives the initial focus - or create the txtFocus control, set the tab index to 0 and tab stop to yes

Edit: For a more system-wide solution, providing you are prepared to have the txtFocusControl on the form, the click event code can be put in a module

Code:
Function chkBoxChange()

    If Not Screen.ActiveControl.Locked Then Screen.ActiveControl = Not Nz(Screen.ActiveControl, False)
    Screen.ActiveControl.Parent.txtFocus.SetFocus
 
End Function

and then called by putting =chkBoxChange() against the click event (replacing [Event Procedure])

I attach a file to illustrate
 

Attachments

  • Capture.JPG
    Capture.JPG
    10.1 KB · Views: 1,755
  • textCheck.accdb
    480 KB · Views: 151
Last edited:

Mark_

Longboard on the internet
Local time
Today, 12:47
Joined
Sep 12, 2017
Messages
2,111
Please note, for most fonts and ASCII 251 will work just fine for a check...√
 

June7

AWF VIP
Local time
Today, 11:47
Joined
Mar 9, 2014
Messages
5,423
Nice. I wonder if something similar could be done with radio buttons in option group.

Couple minor typos:

other that 0

system-wide solution
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:47
Joined
Jul 9, 2003
Messages
16,245
Nice. I wonder if something similar could be done with radio buttons in option group.

It's funny you should mention that June! It's something I'm currently working on, I thought I had finished it, but then I found some issues which I wasn't happy with. I haven't got around to sorting out these issues yet so I haven't published it.

Simulated Option Group - Nifty Access
https://youtu.be/6aHoeOG1f2Q


Simulated Option Group Setup 1 - Nifty Access
https://youtu.be/k1GTGiQOsOA


Simulated Option Group Setup 2 - Nifty Access
https://youtu.be/pA_n5TF2QV8
 

Micron

AWF VIP
Local time
Today, 15:47
Joined
Oct 20, 2018
Messages
3,476
Nice. I wonder if something similar could be done with radio buttons in option group.
I would think you'd need an image control for each option if you want circular radio buttons. Have thought of using images along these lines but never got around to trying anything.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:47
Joined
Feb 19, 2013
Messages
16,553
for radio buttons

false - chr153 - ™
true - chr158 - ž
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:47
Joined
Feb 19, 2013
Messages
16,553
for faces, use wingdings font

happy chr74 J
straight chr75 K
sad chr76 L
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:47
Joined
Feb 19, 2013
Messages
16,553
I wonder if something similar could be done with radio buttons in option group.
not using this method per se with the wizard since the options can only be option/check/toggle controls. But you could still build your own with additional code behind to switch the selection.
 

Minty

AWF VIP
Local time
Today, 19:47
Joined
Jul 26, 2013
Messages
10,355
Very neat, thank you for posting it.

I fiddled around with Windings ages ago to look at a solution for this issue, but time evaporated and I forgot all about it.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:47
Joined
Jan 20, 2009
Messages
12,849
For whatever reason, checkbox controls cannot be resized. This suggestion addresses that issue and also enables the use of colour.

I implemented a similar idea as a Class a few years ago. I intended to get it fully developed and post it but it dropped below the radar and I forgot about it until I just saw this thread.

The Class simplified the setup a lot and easily supports multiple instances. Each instance is completely configured by simply nominating a Textbox and a button that work together to simulate the checkbox. The transparent button simulates a label to precisely emulate the behavior of checkbox labels.

ConditonalFormatting for enabling is supported and also allowed them to work in ContinuousForms. Currently the instance also needs any controls involved in the ConditionalFormat nominated so that it can define the update events that it needs to respond to.

I was working on having the class parse the format conditions so it didn't need the other controls nominated and a collection that could set up and handle events relevant to the simulated checkbox.

I'll get back onto it sometime soon and post here.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:47
Joined
Feb 19, 2013
Messages
16,553
I'm glad people are finding it of interest. I'm just working on a 'dropdown' continuous form for listing fields in a query for users to select which fields they want to search on (or display) - looks a bit like the dropdown for a multivalue combo box - to replace a multiselect listbox I've been using up until now.

I developed the functionality because I wanted a control which was 'finger sized' for touch screen applications and used the underlying value rather than needing code. I previously demoed a multiselect form which is in sample databases so this is really just an extension of that principle.
 

fhsmith

Registered User.
Local time
Today, 14:47
Joined
Jul 18, 2019
Messages
11
Thanks for the tips. I tried the checkbox resize workaround but have problems. I am using access 2002.

I want to expand the size of the check box on a yes/no field placed on a form. The yes/no boxes are too small. I can not get the text box to update the yes/no field in the main table. How do I do this? Many thanks for your assistance.
 

isladogs

MVP / VIP
Local time
Today, 19:47
Joined
Jan 14, 2017
Messages
18,186
@fhsmith
This is a moderated area. Please see the sticky thread about reporting your own post.

I've not tested CJL's code in A2002 but its a very old version of Access and not all functionality may be available in that version.

If you want more specific help to your issue, I suggest you create a new thread, post the relevant code and describe what happened plus any error messages. Include a link back to this thread.

Thanks
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom