By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,480 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,480 IT Pros & Developers. It's quick & easy.

Option Group Radio Buttons

P: 5
Howdy all,
New member, first post.
I've got a form designed to be a scorecard for quality assurance monitoring in a customer service call center. The person I'm kaing the database for wants radio buttons for answering the questions - Yes, No and N/A. I'm good with this.....
The other piece to it is that he wants a way to assign a number value to each radio button to "weight" a particular question differently than other questions.
I can set the OptionValue of any radio button to what ever value he might want, but how to I make it so that he can do it simply? My thought is to have text boxes (hidden until a button "Set Score Weights" is clicked) that would hold what ever values he has chosen.
Is there a way to somehow pass the value of a textbox to set the OptionValue of a radio button? Would the textbox need to be associated with a table?
Would it be simpler to convince bossman to choose some values and do weighting in a "Score" field?
I'm really at a loss as to how to get this done cleanly.
Please help
Nov 19 '08 #1
Share this Question
Share on Google+
5 Replies


ADezii
Expert 5K+
P: 8,597
I'll show you how this can be done for just one Radio Button, and you can figure it out for the other 2. Let's assume that txtSetNAValue will contain the new Option Value for the Button appropriately named optNA. The following code will point you in the right direction, but has 1 Logic Bug and 1 potential problem. I'm going to bed right now, but if you need further help, either in figuring out what the Bug or Problem may be, or any questions regarding the code, either myself or one of the other Experts/Moderators/Members will be happy to Reply.
Expand|Select|Wrap|Line Numbers
  1. Dim lngNAOptValue As Integer
  2.  
  3. 'Must contain a Value, and it must be a Number (LONG)
  4. If IsNull(Me![txtSetNAValue]) Or Not IsNumeric(Me![txtSetNAValue]) Then
  5.   MsgBox "Invalid Entry for Option Value for N/A", vbExclamation, "Invalid Entry"
  6.     Exit Sub
  7. Else
  8.   lngNAOptValue = CLng(Me![txtSetNAValue])     'Must be a Whole Number (LONG)
  9. End If
  10.  
  11. 'Set an Acceptable Range of Values, if an entry goes outside of
  12. 'this Range, enter a Default Value
  13. If lngNAOptValue < 1 Or lngNAOptValue > 500 Then
  14.   Me![optNA].OptionValue = 275       'Assign Default
  15. Else
  16.   'If you get here, you have a Whole Number (LONG) within
  17.   'the Acceptable Range, so use it
  18.   Me![optNA].OptionValue = lngNAOptValue
  19. End If
Nov 20 '08 #2

P: 5
I like the way you help!
I enjoy figuring things out on my own when I can.....I'm glad you left me some stuff to think through.
I haven't tried the code yet (got another fire burning....) but I see something that brings up a question. Will the values in the textboxes stay there? Wouldn't they go away if he shut down the DB and restarted?....or does this code assign the textboxes "default value"?
Part two.....I've got 25 questions, each of which has the option group for answering. Is there a way to write the code once for one option group and have the form loop through the optionGroups and textboxes to get values whent he form is loaded or something?
Nov 24 '08 #3

ADezii
Expert 5K+
P: 8,597
Wouldn't they go away if he shut down the DB and restarted?
Yes they would go away, meaning the new Values would not persist. If you wanted the new Values to persist, try Opening the Form in Design Mode, make the necessary changes, then Close and Save the Form.

Is there a way to write the code once for one option group and have the form loop through the optionGroups and textboxes to get values whent he form is loaded or something?
Here is code that will loop through all the Controls in a Form, if it comes across an Option Group, it will print the Option Group Name as well as the various Options within each Group. I have also demonstrated some sample output for you along with the code.
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2. Dim ctl2 As Control
  3.  
  4. For Each ctl In Me.Controls
  5.   If ctl.ControlType = acOptionGroup Then
  6.     Debug.Print ctl.Name
  7.     For Each ctl2 In ctl.Controls
  8.       If ctl2.ControlType = acOptionButton Then
  9.         Debug.Print "  |-- " & ctl2.Name
  10.       End If
  11.     Next
  12.   End If
  13. Next
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. fraTest
  2.   |-- optYes
  3.   |-- optNo
  4.   |-- optNA
  5. optTest
  6.   |-- Option1
  7.   |-- Option2
  8.   |-- Option3
  9.   |-- Option4
  10.   |-- Option5
  11.   |-- Option6
Nov 24 '08 #4

P: 5
@ADezii
This would negate the "ease" I'm trying to establish. The boss wants to be able to change the values as he see fits, WHEN he sees fit. He would expect the values he inputs on 12/1/08 to remain until......1/17/09 when he decides the values should be adjusted. He doesn't have the know-how, or time to open th form in design view, change default values for 50 textboxes, then save and re-open for use.
What I understand so far is that the code you gave me (which, btw, totally solved another little issue I was having! thank you!) will loop through textboxes for values to use for assigning to the controls in the option groups - assuming someone has entered values into those textboxes once the form was loaded (though, you did make a few lines for default values in the code....).
I think I've got a thought though......would this work?
I've got a form with radio buttons that need to obtain their values independant of the default settings (0,1,2 etc). You gave me code to do that, and code for some nice looping - both of which are housed in the OnOpen or whatever event for the form. Said textboxes are linked to a table that just has the numbers Mr. Bossman has chosen. The button he would click to change those values when he wants would open a form/subform doohickey linked to the table with the numbers - he can change the numbers and a record (perhaps with a date stamp) would be made for each change he does so he can konw how he came up with a score at a particular time......
I'd leave the coded defaults that you wrote in, as a precaution of sorts, and I'd have my values that won't change until bossman wants them to - and I'd have a date stamped record to show the numbers if he flubs somehow!
is this sloppy?
Nov 25 '08 #5

ADezii
Expert 5K+
P: 8,597
This would negate the "ease" I'm trying to establish. The boss wants to be able to change the values as he see fits, WHEN he sees fit. He would expect the values he inputs on 12/1/08 to remain until......1/17/09 when he decides the values should be adjusted.
Expand|Select|Wrap|Line Numbers
  1. As explained previously, to have the Default Values persist, you must Open the Form in Design Mode, 
  2. modify the Defaults, Close the Form, and Save changes, as in:
  3. Dim lngNAOptValue As Integer
  4.  
  5. 'Must contain a Value, and it must be a Number
  6. If IsNull(Me![txtSetNAValue]) Or Not IsNumeric(Me![txtSetNAValue]) Then
  7.   MsgBox "Invalid Entry for Option Value for N/A", vbExclamation, "Invalid Entry"
  8.     Exit Sub
  9. Else
  10.   lngNAOptValue = CLng(Me![txtSetNAValue])     'Must be a Whole Number (LONG)
  11. End If
  12.  
  13. 'Set an Acceptable Range of Values, if an entry goes outside of
  14. 'this Range, enter a Default Value
  15. If lngNAOptValue < 1 Or lngNAOptValue > 500 Then
  16.   DoCmd.OpenForm "frmYourFormName", acDesign
  17.     Forms!frmYourFormName![optNA].OptionValue = 275       'Assign Default
  18.       DoCmd.Close acForm, "frmYourFormName", acSaveYes
  19. Else
  20.   'If you get here, you have a Whole Number (LONG) within
  21.   'the Acceptable Range, so use it
  22.   DoCmd.OpenForm "frmYourFormName", acDesign
  23.     Forms!frmYourFormName![optNA].OptionValue = lngNAOptValue
  24.       DoCmd.Close acForm, "frmYourFormName", acSaveYes
  25. End If
What I understand so far is that the code you gave me (which, btw, totally solved another little issue I was having! thank you!) will loop through textboxes for values to use for assigning to the controls in the option groups - assuming someone has entered values into those textboxes once the form was loaded (though, you did make a few lines for default values in the code....).
No! The code will Loop through all Controls on a Form and if it finds an Option Group, it will list the Controls within that Group along with the Name of the Option Group. The rest I leave to you.
Nov 25 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.