Go Back   Access World Forums > Microsoft Access Reference > Code Repository

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 06-26-2019, 09:15 AM   #1
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 11,343
Thanks: 40
Thanked 3,670 Times in 3,538 Posts
CJ_London is a glorious beacon of light CJ_London is a glorious beacon of light CJ_London is a glorious beacon of light CJ_London is a glorious beacon of light CJ_London is a glorious beacon of light
use a textbox as a resizeable and colourful checkbox

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 2
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)
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])
Attached Images
File Type: jpg Capture.JPG (10.1 KB, 311 views)

__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button

Last edited by CJ_London; 06-26-2019 at 02:18 PM.
CJ_London is offline  
The Following 3 Users Say Thank You to CJ_London For This Useful Post:
fhsmith (07-18-2019), Minty (06-26-2019), Tera (06-26-2019)
 

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Colourful query isladogs Queries 13 01-15-2018 10:15 AM
create a colourful clickable schedule shutzy Forms 7 04-03-2012 12:52 AM
Enabling TextBox upon changes in CheckBox w.rizky Forms 6 11-30-2009 12:14 AM
Show textbox when checkbox checked mickelingon Forms 2 02-08-2006 05:14 AM
link checkbox to textbox jrmywvr Modules & VBA 1 02-07-2003 04:40 PM




All times are GMT -8. The time now is 12:49 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World