Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Option buttons 1

Status
Not open for further replies.

dbflora

Technical User
Apr 16, 2003
13
US
Option Buttons - When I use an option button, it returns a negative 1 value, T/F ot Y/N. Is there some way to have it return a positive 1 value?
 
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?

"The greatest risk, is not taking one."
 
Sounds exactly like what I need to do. How do I incorporate this into the option button for doing a count.
 
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?



"The greatest risk, is not taking one."
 
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.





"The greatest risk, is not taking one."
 
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?

"The greatest risk, is not taking one."
 
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.

"The greatest risk, is not taking one."
 
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.



"The greatest risk, is not taking one."
 
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 is what the code should look like:

Private Sub OptTest_AfterUpdate()
OptTest.Value = Abs(OptTest.Value)
End Sub

Just substitute OptTest with the name of your Option box.


From what I understand, I think you are doing this:

Private Sub OptTest_AfterUpdate()
=[Option10].Value=Abs([Option10].Value)
End Sub

The only thing that would produce would probably be an error.


"The greatest risk, is not taking one."
 
Thank you!!! You have no idea how long this has been bugging me.
 
your welcome


"The greatest risk, is not taking one."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top