Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-31-2017, 05:00 AM   #1
aman
Newly Registered User
 
Join Date: Oct 2008
Posts: 1,250
Thanks: 54
Thanked 3 Times in 2 Posts
aman is an unknown quantity at this point
checkbox value -1 vba

Hi guys

I have couple of checkboxes on my form. When the button is clicked I want to display the values in them. They are showing -1 or null but just wondering it should show 1,0 or true or false.

Any help will be much appreciated.

Thanks

aman is offline   Reply With Quote
Old 05-31-2017, 05:10 AM   #2
bob fitz
AWF VIP
 
Join Date: May 2011
Location: Essex England
Posts: 3,489
Thanks: 50
Thanked 678 Times in 661 Posts
bob fitz has a spectacular aura about bob fitz has a spectacular aura about bob fitz has a spectacular aura about
Re: checkbox value -1 vba

AFAIK they can not be null. Their value can be 0 (False) or -1 (True). See: http://allenbrowne.com/noyesno.html
__________________
Bob Fitzpatrick
Microsoft Community Contributor Award (2011)
If this helped, please click the scales at the bottom left of this posting.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Many thanks.


I have never failed. I have found a thousand ways that do not work!
bob fitz is offline   Reply With Quote
Old 05-31-2017, 05:17 AM   #3
plog
AWF VIP
 
Join Date: May 2011
Posts: 9,351
Thanks: 10
Thanked 2,272 Times in 2,224 Posts
plog is a jewel in the rough plog is a jewel in the rough plog is a jewel in the rough
Re: checkbox value -1 vba

Checkboxes on a form can be null. You should code such that those checkboxes are not null. You accomplish this by setting a default value to them.

As for why -1 is True and 0 is false, you can search this forum for lengthy, boring discussions with each new poster trying to outdo the others with their knowledge. I advise you to just accept that's the way the world works and know that -1 is true and 0 is false.

plog is offline   Reply With Quote
Old 05-31-2017, 01:27 PM   #4
Cronk
Newly Registered User
 
Join Date: Jul 2013
Posts: 2,137
Thanks: 3
Thanked 466 Times in 459 Posts
Cronk will become famous soon enough Cronk will become famous soon enough
Re: checkbox value -1 vba

"As for why -1 is True and 0 is false..."

Yes, for binary but any value other than -1 is true in logic operations.

However, check boxes can hold values other than 0, null or -1. I found this out some years ago doing some enhancement work on a database I had not created where an unbound check box was being used to store a date and it showed on the form as being checked. Go figure why it was done this way.
Cronk is offline   Reply With Quote
Old 05-31-2017, 05:43 PM   #5
The_Doc_Man
Happy Retired Curmudgeon
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 14,367
Thanks: 87
Thanked 1,644 Times in 1,526 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
Re: checkbox value -1 vba

Cronk, I think any other value than 0 is TRUE. You said it backwards.
__________________
I'm a certified grandpa (3 times now) and proud of it.
Retired over one year and survived being home all day with the wife. She must really love me.
If I have helped you, please either click the thanks or click the scales.
The_Doc_Man is offline   Reply With Quote
Old 05-31-2017, 11:33 PM   #6
Galaxiom
Super Moderator
 
Join Date: Jan 2009
Location: NSW Australia
Posts: 11,607
Thanks: 89
Thanked 1,492 Times in 1,408 Posts
Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold
Re: checkbox value -1 vba

Quote:
Originally Posted by plog View Post
As for why -1 is True and 0 is false, you can search this forum for lengthy, boring discussions with each new poster trying to outdo the others with their knowledge. I advise you to just accept that's the way the world works and know that -1 is true and 0 is false.

This is one of the threads plog refers to.

Personally I found it quite interesting but then I am a curious person and like to understand what is behind things. Moreover I consider it sharing knowledge rather than a competition.

Anyone who bothered to take the time to understand would see that my explanation in post 9 of that thread actually does comprehensively explain why negative one is used for True.
Galaxiom is offline   Reply With Quote
Old 06-01-2017, 02:38 AM   #7
Orthodox Dave
Home Developer
 
Orthodox Dave's Avatar
 
Join Date: Apr 2017
Location: London UK
Posts: 218
Thanks: 25
Thanked 51 Times in 50 Posts
Orthodox Dave will become famous soon enough
Re: checkbox value -1 vba

If you really must show something on your form other than a tick in a box, you could

1. In your main table, change the yes/no field type to Byte.

2. On your form put a combo or list box with a VALUE LIST of 2 columns, with a row source such as:
0;"Not as Such";1;"Yes Definitely" [Don't use -1 as the Byte type won't accept it]

3. The bound column is column 1 and its column width is 0", so the 2nd column is displayed.

__________________
Dave

The simplest solutions
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
can be the hardest to find
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Orthodox Dave is offline   Reply With Quote
Old 06-01-2017, 02:47 AM   #8
Cronk
Newly Registered User
 
Join Date: Jul 2013
Posts: 2,137
Thanks: 3
Thanked 466 Times in 459 Posts
Cronk will become famous soon enough Cronk will become famous soon enough
Re: checkbox value -1 vba

Doc

Your comment "any other value than 0 is TRUE". Seems any value other than -1 equates to false.

? (1 = true)
False

? (0 = true)
False

? (-1 = true)
True

? (-1.1 = true)
False

Glaxiom, you refer to your post that "True is determined as Not 0"
In fact (Not anything) except (Not -1) is true

Last edited by Cronk; 06-01-2017 at 02:57 AM.
Cronk is offline   Reply With Quote
Old 06-01-2017, 03:01 AM   #9
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,393
Thanks: 112
Thanked 2,851 Times in 2,598 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: checkbox value -1 vba

Its deja vu all over again ....
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 06-01-2017, 03:13 AM   #10
static
Newly Registered User
 
Join Date: Nov 2015
Posts: 823
Thanks: 4
Thanked 194 Times in 180 Posts
static will become famous soon enough static will become famous soon enough
Re: checkbox value -1 vba

Debug.Print CBool(1)
Debug.Print CBool(0)
Debug.Print CBool(-1)
Debug.Print CBool(-1.1)
Debug.Print CBool("true")
Debug.Print CBool("false")
Debug.Print CBool("yes") ' err 13
Debug.Print CBool("no") ' err 13

_
static is offline   Reply With Quote
Old 06-01-2017, 03:58 AM   #11
Frothingslosh
Premier Pale Stale Ale
 
Frothingslosh's Avatar
 
Join Date: Oct 2012
Location: Flint, Michigan, USA
Posts: 3,211
Thanks: 83
Thanked 456 Times in 413 Posts
Frothingslosh will become famous soon enough Frothingslosh will become famous soon enough
Re: checkbox value -1 vba

Static: 15
Cronk: Love

Static has the serve.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Frothingslosh is offline   Reply With Quote
Old 06-01-2017, 04:16 AM   #12
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,393
Thanks: 112
Thanked 2,851 Times in 2,598 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: checkbox value -1 vba

Quote:
Originally Posted by frothingslosh View Post
static: 15
cronk: Love

static has the serve.
lol
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 06-01-2017, 04:33 AM   #13
Frothingslosh
Premier Pale Stale Ale
 
Frothingslosh's Avatar
 
Join Date: Oct 2012
Location: Flint, Michigan, USA
Posts: 3,211
Thanks: 83
Thanked 456 Times in 413 Posts
Frothingslosh will become famous soon enough Frothingslosh will become famous soon enough
Re: checkbox value -1 vba

Yeah, yeah, I capitalize names out of habit. :P
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Frothingslosh is offline   Reply With Quote
Old 06-01-2017, 10:08 AM   #14
The_Doc_Man
Happy Retired Curmudgeon
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 14,367
Thanks: 87
Thanked 1,644 Times in 1,526 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
Re: checkbox value -1 vba

Cronk: Remember that constant name "TRUE" is -1 and "FALSE" is 0, and ALSO remember that for expressions to be evaluated, automatic promotion occurs to force compatibility for the subsequent comparison.

? (1 = true)
False
because 1 is not equal to -1.

? (0 = true)
False
because 0 is not equal to -1.

? (-1 = true)
True
because -1 IS equal to -1.

? (-1.1 = true)
False
because -1.1, being at least a SINGLE, requires conversion of -1 to -1.0, which is NOT equal to -1.1.

Static was doing this the other way - taking the constants and converting them to their Boolean values to see how they react. In other words, you were doing things in a way to allow typecasting to higher types; he was testing in a way that forced typecasting to lower types.
__________________
I'm a certified grandpa (3 times now) and proud of it.
Retired over one year and survived being home all day with the wife. She must really love me.
If I have helped you, please either click the thanks or click the scales.
The_Doc_Man is offline   Reply With Quote
Old 06-01-2017, 12:35 PM   #15
plog
AWF VIP
 
Join Date: May 2011
Posts: 9,351
Thanks: 10
Thanked 2,272 Times in 2,224 Posts
plog is a jewel in the rough plog is a jewel in the rough plog is a jewel in the rough
Re: checkbox value -1 vba

Just posting back to let everyone know I'm not one of those people who is above saying 'I told you so':

I told you so.

plog is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to Update checkbox if another checkbox is ticked! Tigereyes Forms 1 05-25-2012 07:22 AM
Need to autocheck combo box checkbox when another checkbox is checked off in combobox pampers4u Modules & VBA 1 10-01-2010 10:58 AM
Address -> Checkbox, Checkbox -> Adress Roadguru General 2 09-26-2008 12:46 PM
update checkbox based on value in another checkbox lscheer Modules & VBA 2 11-07-2002 11:26 AM
controlling one checkbox with whats in another checkbox...? bengy Forms 1 04-04-2002 08:51 AM




All times are GMT -8. The time now is 09:59 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