View Full Version : Select An Option Button With Code


DavidWE
02-09-2009, 09:04 AM
I have two option buttons - optYes and optNo. The user can select one. Is there a way to select one of the options using code depending on the value of a variable? I would want optYes to be selected if the variable PRStatus = "Y". If PRStatus = "N", optNo is selected.

If not, can I do this with a check box or another control?

It should look something like this:


If PRStatus = "Y" Then
[optYes is true/selected]
[optNo is false/not selected]
ElseIf PRStatus = "N" Then
[optNo is true/selected]
[optYes is false/not selected]
End If


Thanks

Uncle Gizmo
02-09-2009, 09:16 AM
Are the option buttons part of a group?

If they are, then is this group bound to a field in the table?

KenHigg
02-09-2009, 09:22 AM
Can you set the PRStatus field to a yes/no data type and use it as the control source for a check box to turn it on/off?

DavidWE
02-09-2009, 09:23 AM
The option buttons are part of a group but are not bound to fields in a table.

Thanks for responding.

DavidWE
02-09-2009, 09:30 AM
I should have included in my first post that the group name is grpPRStat. I am now trying to see if I can set grpPRStat to "1" or "2" depending on the value of the variable.

Ken: I'll also try your suggestion.

DavidWE
02-09-2009, 09:43 AM
Thanks Uncle Gizmo and Ken. Both of your posts got me on the right track. For some reason I was forgetting I can manipulate the options on the group level rather than trying to change each option individually.

This works:

If PRStatus = "Y" Then
grpPRStat.Value = "1" 'optYes has the value "1"
ElseIf PRStatus = "N" Then
grpPRStat.Value = "2" 'optNo has the value "2"
End If

KenHigg
02-09-2009, 09:44 AM
Glad you have it working -