Access defines a selection in a check box as -1. If you want a positive 1 to do calculations or counts, then you can use the ABS function. ABS(variant). This will turn any negative number into positive. Is this what you need?
Well it depends where you want to do the count. You could:
In a query, count all the records with -1,
Or you could sum them up with the ABS to get a total,
You could have it save in the table as Abs(Checkbox.value) in a field.
What exactly do you want to do? When and where do you want to see the count?
First, thanks for the help. Second what I am trying to do is have the -1 show up as +1 on all tables and reports I run. I have 4 option buttons to choose from and I would like to have the one that is checked return the 1 and the others 0 so I can calculate totals.
I suppose that your form is bound to the table that it is saving to, so once you make a change, it automatically updates that table. I'm not sure exactly how you have it set up, but you could have each option button to change it's value by creating an even on the AfterUpdate section by writing this:
YourOptionBox.Value = ABS(YourOptionBox.Value)
this will take whatever the value is, and make it positive. Let me know if this helps, or if you're saving to an unbound source.
I think I'm close. I keep getting "error evaluating check constraint" errors. You are correct in that the form is bound to the table. I am setting a button (option 61) with =[Option61]=Abs([Option61] in the AfterUpdate section. Am I douing it incorrectly?
Well, you shouldn't get an error for that. Do you have an option group? Is there one Option button per field?
Where and where exactly are you getting the error message? If you use a button, then you'l need to put it in CLick event. What do you want the button to do?
I tried putting it in click event, same results. The error comes when I try to save or exit the form. I've got the option buttons set up in an option group and they are linked to seperate fields. I need to have it return a 1 or a zero into the appropriate field.
That's odd. It should have something to do with your data requirements that you have set, and it not being able to determine if they were filled. look at them closely. The problem could be in the option itself or perhaps in the table field properties. look into it and get back to me.
I think there was an error somewhere else on the form. I have started over. To simplyfy I just created one field and on the form and attched it to a seperate table. I inserted one option button and tied it to the same field. When I click the option button, the field in the form and on the table populates with a zero when the circle is empty and -1 when I have filled in the circle by clicking it. Now is it possible to change that -1 to a 1?
Sorry for the delay, I was gone. But now with that new form, if you do the:
YourOptionBox.Value = Abs(YourOptionBox.Value)
On the AfterUpdate event, it should work.
If not, let me know and i'd like to take a look at your form if you'd let.
Nope. Maybe I am not entering in the correct expression.
I put =[Option10].Value=Abs([Option10].Value) in the AfterUpdate event and nothing. Is that correct? At least there was no error message this time.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.