Option Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use option buttons that are grouped. The problem I am having
is I cannot figure out how to have one of the option buttons selected on
start up. Here is what I need to do.

Form_Load()
optbutton.value = true
end sub

But this does not work. I get a run time error. "Can not assign value to
this object"

Any suggestions
 
To group them you have to have put them in a frame (you do have them in a
frame, right??). Frames are also sometimes referred to as an option group.

For them to work in a frame, they each have a separate value (e.g., the
first button has value 1, the second button has value 2, etc.) and you then
test the value of the frame to find out which button has been pushed. In
fact, it's the frame that's bound to your table/query and not the individual
buttons.

If you look on the property sheet for the frame, you'll find a default value
property. You put in there the value that's been assigned to the button
that you want as your default.

In fact, in general, you can't access the individual buttons in a frame.
 
Hey they are in a frame. I guess my question is how do I know which one is
selected. I want to do this .

if optComputer is selected then
run this report
end if

I am not sure how to set up the if statement.
 
Assuming you have an option group set up correctly (if you're having trouble
use the wizard) you can use this function to retrieve the name of each radio
button in the wizard (that means you have to name each button)

Function FindName(OptionGroup) As String
Dim j%, val%
val = OptionGroup.Value

For j = 0 To OptionGroup.Controls.count - 1
If OptionGroup.Controls.Item(j).ControlType = 105 Then
If OptionGroup.Controls.Item(j).OptionValue = val Then
FindName = OptionGroup.Controls.Item(j).name
End If
End If
Next j
End Function

From wherever Sub you're trying to get the name from call the function (the
option group name is the arguement)

eg.
Sub Opt_Group_Click()
dim str as string
str = Findname(me.opt_group)
end sub

If you're not using radio buttons in your option group you will have to
change the "105" to the appropriate control type.

Good Luck
 
I am trying to use option buttons that are grouped. The problem I am having
is I cannot figure out how to have one of the option buttons selected on
start up. Here is what I need to do.

Form_Load()
optbutton.value = true
end sub

But this does not work. I get a run time error. "Can not assign value to
this object"

Any suggestions

I've read the rest of this thread.

First, set the default in the Properties box of the Option Group. On
the Data tab enter the value of the Option you want as the default
(ex. 1)

Below is a quickie bit of code in a simple form module to show how to
get the value of the selected option. Just change the message box
junk to some DoCmd.OpenForm code and you shold be good to go.
All this form had was an Option Group and a Command Button.

Private Sub cmdOpenReport_Click()
Dim MyOpt
Dim strPrompt As String, strTitle As String

strTitle = "Option Example"

MyOpt = Me.OptFrame.Value
Select Case MyOpt
Case 1
strPrompt = "Printing Issue Report. Option: "
Case 2
strPrompt = "Printing Resource Report. Option: "
Case 3
strPrompt = "Printing Financial Report. Option: "
Case Else
End Select

MsgBox strPrompt & MyOpt, , strTitle

End Sub


HTH,
RD
 
That worked! Thank you, kabaka, and jp I have been working on these all day.
I am used to writing C# stuff. Thank you again!!!
 
Back
Top