Assigning value to checkbox

  • Thread starter Thread starter rtomalin
  • Start date Start date
R

rtomalin

Guest
I think this should be a simple question, but I just cannot figure it out. I have a form which contains a check box. I want to set the value of a field in a table to 0 if the box is unchecked and 1 if the box is checked.
How can I do this

:confused:

Thanks
R Tomalin
 
Why not change the field to a Yes/No field and bind it to the checkbox?
 
Make a field name in a table - Data Type will be number and Format it to long interger and set your default value to -1. When inserting your field in a form be sure you set it to a checkbox field instead of textbox.

hth,
Michael
 
Thanks for the feedback but I think that the respondants have misunderstood. The field value in the table MUST be 1 or 0. So setting the field to yes/no will not work. Neither will setting the default value to -1.
It's easy to use a check box to set the table value to yes/no (using yes/no data type) or to -1 or 0 (using number data type).
But I need to set to 1 if the check box is ticked and 0 if the box is not ticked.

Regards

Richard
:confused:
 
rtomalin said:
But I need to set to 1 if the check box is ticked and 0 if the box is not ticked. :confused:
But surely it doesn't matter - whatever value it places in the table will be meaningless to the users, you will still need to interpret what 1 or 0 means to the users

Col
 
And In a query, all you need to do is multiply 0 or -1 by -1 and you have either 0 or 1. ;)
 
Rich said:
Why not just Abs([YourField]) ? :confused:

The two suggestions (using Abs or mult by -1) in subsequent reporting on this field would be fine - I had sort of considered doing that, but thought it a bit clumsy.
My sense of order would be more satisfied if the actual value stored in the table was correct for the application, which is that the form asked if a passenger has an escort. Tick means yes and the "number of escorts" is set to 1. Then subsequent reporting is simple and I don't have to remember to apply a calculation.
Furthermore, in my ingnorance (I am fairly new to Access) I had assumed that you could use a little bit of simple code somewhere to set a value for the field (text or number) dependant on the checkbox on the form. Is this not possible?
Alternatively is it possible to apply the Abs function to the value before it is stored in the table. If so, how?

Thanks again

Richard
 
You could program in identifier in Visual basic code,
so...

checkbox_onclick
if checkbox = true then change a field Value to 1
if checkbox = false then change a field value to 0
end sub

Im not sure if you can use field that are invisable however, so you may have to put the field off the userable form,
 
KaiProton said:
You could program in identifier in Visual basic code,
so...

checkbox_onclick
if checkbox = true then change a field Value to 1
if checkbox = false then change a field value to 0
end sub

Im not sure if you can use field that are invisable however, so you may have to put the field off the userable form,


Hello,

Thanks for your help guys - but I figured out the solution.
I just set the Format property of the table field to:

0;\1

(not sure why Access puts in the "\")

Then - if the check box is blank the field is set to 0 and if the box is checked the field is set to 1.

Thanks and regards

Richard
:)
 

Users who are viewing this thread

Back
Top Bottom