View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Groups in Option buttons

When you say "determine which is selected", if you mean literally that use
ActionControl but see below for testing if in a frame
If you mean determine which optionbutton is 'true' you'll need to poll all
Optionbuttons in the frame or group.you are interested in.

You can refer to a control by it's index number (instead of its name) which
is set at design time and will never change. It'll be the nth item placed on
the form counting from zero and also the m'th item if say in a Frame. Where
a control is in a container such as a frame it will have two index numbers,
one that relates to the form and another to the nth control on the frame.

frm.controls(n)
frm.Frame1.controls(m)

Pick anything of use in the following, assumes a Frame on a form containing
some optionbuttons and other controls on the form, perhaps also
optionbuttons.

Private Sub UserForm_Click()
Dim ctr As Control, ob As MSForms.OptionButton

If TypeName(Me.ActiveControl) = "Frame" Then
Set ctr = Me.ActiveControl.ActiveControl
Else
Set ctr = Me.ActiveControl
End If

MsgBox ctr.Name, , ctr.Parent.Name

MsgBox Me.Frame1.Controls(0).Name

'if you are certain the frame only contains optionbuttons
For i = 0 To Me.Frame1.Controls.Count - 1
With Me.Frame1.Controls
Debug.Print .Item(i).Caption, .Item(i).Value
End With
Next


For i = 0 To Me.Controls.Count - 1
Debug.Print i, Me.Controls(i).Name
Next

End Sub

Regards,
Peter T


"Dale Fye" wrote in message
...
Similar issue.

I have a frame (vb toolbox) on a UserForm. Have two OptionButtons in the
frame.

In Access, each of the option buttons would have a numeric value, and I
would refer to the frames value to determine which OptionButton was

selected,
and to set them via code.

Is there a simple way to do this in Excel? I've got several more of these
and would like a quick and easy way to determine which is selected and to

set
them via code.

Dale
--

email address is invalid
Please reply to newsgroup only.



"Rick Rothstein (MVP - VB)" wrote:

Where did your OptionButtons, GroupBox and TextBox come from (the Visual
Basic or Forms Toolbar; or, perhaps, you are using a UserForm)? I ask
because the Forms' Toolbar has a GroupBox but no TextBox whereas the

Visual
Basic Toolbar calls its "group box" a Frame and does have a TextBox. Or

are
you mixing components from both Toolbars?

Rick


"Greg B" wrote in message
...
Yeah I didn't make much sence sorry, I have a group of 7

optionbuttons in
a group called "expenses".
Instead of going throught all with the code for each individual

optionbox,
I was wondering if there was a way to have the selected box put it's
caption into a textbox called reason.

Hope that is a bit more understandable.

Thanks Again
Greg
"Peter T" <peter_t@discussions wrote in message
...
Hi Greg,

Is that Option buttons on a form to which you have assigned a

GroupName
property,
or
Forms OB's on a sheet, which you have Grouped or placed in a GroupBox
Or
ActiveX OB's on a Sheet which you have done either of the above or

given
GroupNames

After clarifying the above, explain that you mean by -

"I am looking to have reason.text show the answer."

What is "reason", what do you have in mind for the "answer"

Regards,
Peter T


"Greg B" wrote in message
...
I would like to know how I can get the data from a group of option
buttons.
I have a group of 8 optionbuttons with the names "e1" through to

"e8",
the
name of the group is "expenses" I am not sure how to use or if I

can
use
a
groupname vba. I am looking to have reason.text show the answer.
Or do I have to go through and write if e1.value = true then.....

thanks in advance

Greg