Adding option buttons

teiben

Registered User.
Local time
Today, 22:56
Joined
Jun 20, 2002
Messages
462
I have several option button on a form, (Placed in an Option Group Frame) that I need to add the values of. For example Option234 = 2 (yes value), Option236 = 1 (partial) and Option238 = 0 (no value).

I created a text box calculate control and set the Control Source to
=Sum([Option234]+[Option236]+[Option238])
but I keep getting that #Name?
Is it not working becuase it's in a Option group frame?
 
If your buttons are part of an Option Group, then you'll only have 1 of those buttons 'checked' at a time.

Set your text box = (name of your option group frame)

The frame of the option group is the control that holds the value from whichever option button has been clicked.

HTH,
John
 
I tried
=Sum([Frame232])
Frame232 contains the 3 option buttons Option234 = 2 (yes value), Option236 = 1 (partial) and Option238 = 0 (no value), which does not work, how would I code it?
 
I guess I don't understand why you're trying to add those values together if only 1 of them is chosen...

If you're just looking to see which value is chosen then ditch the sum:

=Frame232

Otherwise, you'll have to explain a bit more what you're trying to do.

Regards,
John
 
Becaue there are 10 on the form, so I need to add each of them up.
 
Please elaborate:

1) Are there 10 frames or 10 option buttons?

2) Are all your option buttons contained in an option group(s)?

If you have multiple option group frames and all your buttons are contained within them, then your expression would be as follows:

=Frame232 + Frame233 + Frame 234

BTW, you may want to consider renaming your controls with descriptive names according to db naming convention (using prefix of 'fra' for frames, 'opt' for option buttons, 'txt' for text boxes, etc).

HTH,
John
 
There are 16 frames; Each frames consists of 3 option buttons. For each they are yes=2; partial=1 and no=0; These values are succesfully beign stored. I just need how to add them up.

I need the grand total of what's in frame1 thru 16
 
Well, without getting into VBA, the only solution that occurs to me is to carry-out my example for all 16 frames - type in the name of each frame in your expression adding it to the expression string.

I'm a bit concerned that you're using this many frames on your form. There may be a way to design your UI (or db) more efficiently. I can't offer any pointers though since I don't know what your main purpose to the database is.

HTH,
John
 
Thanks anyway, (I think I already tried that); It's a checksheet w/yes no or partial values that have questions attached to it. I was wondering the same thing (how effeciently the thing will run)
 
My solution will work as long as you set a default value to each frame. Otherwise, if nothing is selected for that frame, it returns a Null value, which will propagate through your sum (you'll get no result for a grand total).

Are you using one of the options as a default value? If not, either re-assign your option values to 1=No, 2=Partial, 3=Yes, with your default setting = 0, or assign one of the options as the default (0, 1, or 2).

Don't throw in the towel yet!;)
 
I think your Brilliant; I went though and changed the default of the frames to 0;

Now it reads =([15Results]+[14Results]+[13Results])

the result is 102, becuase it's not adding; I'm in a form, I tried the obvious sum,
=Sum=([15Results]+[14Results]+[13Results]) and that doesn't work, got any idea?
 
You lost me again - did you get it to work or no?

Looks like you renamed your frames - is this true?

Please be specific in your response
now it reads =([15Results]+[14Results]+[13Results])
- Is 'it' referring to your textbox ControlSource expression or the value displayed in your textbox?

'Sum' is not the correct function to use in this case since you're already adding the frames together (you're attempting a redundant calculation).

Getting There!
 
the control source of my textbox

=([15Results]+[14Results]+[13Results])
 
Doesn't quite work; I renamed the option group to 15Results, 14Results, etc.
 
You're getting a number result in your text box, though?

Please advise if you're still stuck (and what the problem is exactly), otherwise if you can handle it from here I'll put this case to bed.

Regards,
John
 
The problem is it show 102 which is a 1 value in results15, a 0 value in result14 and a 2 value in results13. In other words it is just displaying them. I don't get it and it's probably something stupid.
 
The ControlSource for your frames is set to fields whose DataType is text. You'll have to change the underlying field's datatype for each frame's ControlSource to one that has a number datatype.

That's gotta be the problem :cool:
 
Excuse me for jumping in, but this
is becoming painful.

Here's a small working/tested example.

Form9 has:
Three option groups: Frame1, Frame2, Frame3;
each group has three options: No=0, Partial = 1, Yes = 2

Command button: cmbGo

Text box: Text0

Here's the code for cmbGo's OnClick event:
Code:
Private Sub cmbGo_Click()
Dim intHold As Integer
Dim n As Integer
Dim namehold As String
For n = 1 To 3
   namehold = "Frame" & Format(n)
   intHold = intHold + Me(namehold)
Next n
Me!Text0 = intHold
End Sub

Suggest you spend a couple of minutes setting
it up and testing.

If you can't make it work, suspect the problem is
in how the option groups are being created.
Use the wizard to set up the first group.
Copy/paste this group however many times you
need, then go back and rename the groups
sequentially and change the labels accordingly.
 
Raskew,

Apologies for drawing this one out, but I didn't want to resort to code for teiben's sake.

The solution is all in place now anyway - the only way the text box could treat the frame values as strings is if the frames had text fields as ControlSources.

Slick piece of code, though :cool:

Cheers,
John
 
Thanks for all the help. I'm sorry for "dragging this one out". I will try and figure out the code provided. (I don't get how text box could treat the frame values as strings is if the frames had text fields as ControlSources) but that's ok.

Thanks for the help
 

Users who are viewing this thread

Back
Top Bottom