Reference Option Name within Option Group

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

Guest

Hi,

I have a form with an option group with 16 options in the group. Within my
code I would like to either reference the selected option's label caption or
the selected option's name (which I can make identical to the label).

I have a command button that opens a popup form that will utilise the
option's caption.

I know I can use a select case statement to achieve this, however there must
be a more efficient method to access an option's name or associated label's
caption.

Thanks in advance,
Dave
 
I think you will have to loop through the option buttons to match their
OptionValue against the Value of the group.

Once you have a match, the option button's attached label is the first (and
only) member of its Controls Collection, and that label has a Caption
property.

So:

Dim strCaption As String
Select Case Me.MyGroup.Value
Case Me.opt1.OptionValue
strCaption = Me.opt1.Controls(0).Caption
Case Me.opt2.OptionValue
strCaption = Me.opt2.Controls(0).Caption
...
 
Dave:

Here is one approach:

If your properties are set up similar to:
optButton01.OptionValue = 1
optButton02.OptionValue = 2
....
optButton16.OptionValue = 16
then
strControlName = "optButton" & Format( fraOptionGroup.Value,"00")
Me.Controls(strControlName)

should point to the selected control (or the control representing the
default value of the group).

You could store the "name" value in the Tag property of the button and
bypass referencing the associated label, or use the suggested numbering
scheme for the labels and have strControlName point to labels rather than
buttons.
 
Thanks Allen, that worked nicely.

Now to figure out how to pass that caption to my popup form?!?
 
The problem is that you open your form in dialog mode, which pauses the rest
of your code so you cannot pass a value?

You could either put your code into the popup form's module (i.e. read the
other form, substituting "Forms!Form1" for "Me"), or pass the caption in the
OpenArgs of your OpenForm.
 
Back
Top