Changing Yes/No CheckBox Value (1 Viewer)

MsfStl

Registered User.
Local time
Today, 05:36
Joined
Aug 31, 2004
Messages
74
Hello all,

I am creating a survey that has many boolean (Yes/No) check boxes. The problem is, the values we want to use are (0,1) instead of (0,-1 Access defined).

First question, can I preset the True/False values differently than what Access has them? That would be my best case scenario.

If not, from what I can see I could just change the chkbxs to Number (instead of Y/N) data type and then use the ABS() , absolute, function to get 0 and 1. Is there a better way to do this? Or do I even need to change them to Number data type?

IF the Abs() function is the way to go, is there a way to code a macro, or is there a macro, that would run through all the controls with 'chk' in the name and then run the Abs() function rather than calling it for every CheckBox control?

Did any of that make sense?

I do appreciate your time!
 
R

Robgould

Guest
I don't know how to change the numbers, but you can use "true" and "false" instead of numbers. Don't know if that helps you.
 
R

Robgould

Guest
I am creating a survey that has many boolean (Yes/No) check boxes. The problem is, the values we want to use are (0,1) instead of (0,-1 Access defined).

First question, can I preset the True/False values differently than what Access has them? That would be my best case scenario.

Thought about it some.....

You could do something like this. It would change your output to a 0 or 1, but I'm not sure how you want to use it after that. You would have to put the code in the change, or update envents. It may become a real pain trying to go back and forth all the time.

Code:
dim myval as string

if me.checkbox = -1 then
myval = 0
else
myval = 1
end if
 

MsfStl

Registered User.
Local time
Today, 05:36
Joined
Aug 31, 2004
Messages
74
Yeah, I thought about doing that, but that would require at least creating a function and calling that for every check box. Plus, fyi, you posted:

dim myval as string

if me.checkbox = -1 then
myval = 0
else
myval = 1
end if


I would do two things different:
1) Leave the myval as a variant rather than a string, because otherwise I would have to convert those later to numbers

2) reverse to true and false statements :
if me.checkbox = -1 then
myval = 1
else
myval = 0
end if


Access to my knowledge only allows 0 as a false/no/off and anything else as true/yes/on.

However, thank you very much for replying, any thoughts on this are greatly appreciated!

Which brings me to the macro question again. Is there a code to run through all controls on a form and validate or update their values, without having to code a call for each control individually?
 

selenau837

Can still see y'all......
Local time
Today, 06:36
Joined
Aug 26, 2005
Messages
2,211
MsfStl said:
Which brings me to the macro question again. Is there a code to run through all controls on a form and validate or update their values, without having to code a call for each control individually?

Yes you can code to go through the control collection

Dim ctl as Control

For Each ctl in me.controls

if ctlControlType = acCheckBox (?) then

if me.ctl.value = -1
myval = 1
else
myval = 0
end if

end if



next ctl

The above goes through all controls on your form, and if it is a check box, it then performs the action you place inside that loop. May want to check the code inside the loop, not sure if that is correct, but will give you an idea of what I am talking about.
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
hey guys. . maybe you can help me . . i think i got a similar problem
how can i change the value of a checkbox. . change the value to text ?
what i'm trying to do is search people on my table. . by unemployed people. .
i done this check box to select all unemployed people..

hope you can help. . (sorry about the terrible english
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 11:36
Joined
Sep 7, 2009
Messages
1,819
Check boxes return either true or false. Why do you want to change it to text? Just do a query on your table to say "select records where unemployed=true", have the unemployed field in your table as a yes/no and the check box control on the form bound to that.
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
oh, thanks. . .
But I'm not really sure how to do that query .. . I'm a beginner you know. .
So can you help me on that?
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 11:36
Joined
Sep 7, 2009
Messages
1,819
OK - if you haven't got an 'unemployed' yes/no field in your table, create it. Then, create a query based on this table. Drag down the fields you want, and also the new 'unemployed' field. In the criteria of the unemployed bit, put "True" if you want the ones that are selected, or "False" if you want the ones where it's not selected.

Bear in mind of course that if you've just created the 'unemployed' field they'll all be set to False, so you'll have to go into the table and tick boxes as necessary.
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
Well I must have done something wrong. ..
Now, when I try to open the main form a little window warning appears saying 'Data type mismatch in criteria expression'

what is wrong?

(I don't want to bother you, I really don´t :p
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 11:36
Joined
Sep 7, 2009
Messages
1,819
So - what criteria have you got in there? Data type mismatches usually mean you're using text criteria in a number field, or a non boolean in a yes/no field.

Just to confirm - you've got a field called 'unemployed' in your table, which is defined as a yes/no type field. You've created a blank query based on this table, dragged down the fields you want, including the 'unemployed' field - and in the criteria of this field, you've put True. Correct? Don't surround True in quotes - it's a boolean value, not a string. (Boolean is just true/false, or -1/0, or yes/no - however you want to put it)

And you're not bothering me, honest - I wouldn't reply if you were :)
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
It was surrounded by quotes, but it wasn´t me. :) really.
now. . another problem. :p
The way i did only appears the contacts of the unemployed people, even before i search. ..
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 11:36
Joined
Sep 7, 2009
Messages
1,819
Sorry, I was a bit trigger happy on the quotes.. my fault

Have a look in the table - pick a record of someone you know who is unemployed. Is the 'unemployed' tick box ticked? If it is, and in the query you've set the criteria to True, it should come up in the query result.

Try is as False and see what it comes up with too.
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
well, I guess I know what is wrong.. but I don´t know how to solve the problem. .
I drag the field like you said
. but that field is separated from de others fields. ..
the others fields are all together. . it's something like. . ''File as: blá bla´blá''
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 11:36
Joined
Sep 7, 2009
Messages
1,819
File As? Where are you seeing that?? Is that the name of a field in your table?

Let me explain the steps. First of all I'm presuming here that you have a table with say, name, address, unemployed (as a yes/no field in the table's design)

1. Create a blank query
2. Add your table
3. Drag down name and unemployed
4. In the criteria of unemployed, put True
5. Run the query

It will display the names of the people in the table, where unemlpoyed is True.

Follow steps 1-4 and before you run it take a screen shot and post here so we can make sure we're on the same page.
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
something like this:


Desempregado means unemployed. It's Portuguese
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 11:36
Joined
Sep 7, 2009
Messages
1,819
Can't see it, you'll have to upload the file
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
okay ;) .........
 

Attachments

  • Sem Títulorrr.jpg
    Sem Títulorrr.jpg
    94.2 KB · Views: 175

JamesMcS

Keyboard-Chair Interface
Local time
Today, 11:36
Joined
Sep 7, 2009
Messages
1,819
OK Just to get the query working so you can see what I mean, just follow the steps above instead of putting iifs in and whatnot. So basically for now create a new query based on Contacts, as you've done. Then, just so you can see what's happening, Drag down ONLY "Nome" and "Desempregado", and as you've done, put True in the criteria. This will bring back only the Nome of anybody who has Desempregado=True. (Again bear in mind that you need to tick some of the Desempregado check boxes in the table otherwise you won't see anything).

The IIf's you've got in there are another matter. Create a new thread for these so we can get off this hijacked one :)
 

tgei346

Registered User.
Local time
Today, 11:36
Joined
Jun 4, 2010
Messages
18
My god. .. :mad:
I understand what you mean, but I just can't make it work :S
Do you mind if i send you the file so you can correct my whole mistake ?. . :S

I done the query, but when I write 'True' on 'Nome' field, the quotes just appear from nowhere. .. but the same didn't happen on 'Desempregado' field.

Sorry, my English is too terrible .
 

Users who are viewing this thread

Top Bottom