optiongroup optionbutton (possibly no-brainer)

  • Thread starter Thread starter rmanchu
  • Start date Start date
R

rmanchu

when a optionbutton in an optiongroup is clicked, what's the quickest
way to get the actual *optionbutton* *control* that was clicked?

i'm probably missing a very easy to use property here right? or do i
have to loop thru the .Controls collection to find the optionbutton
with the right value?

thanx
riyaz
 
I use a Select Case, either in a sub or in the afterupdate of the
optiongroup, like
Select Case Me.frameType.Value
Case 1
TT = "you clicked on the first option"
Case 2
TT = "You clicked on the 2nd option"
etc....
The values are on the property sheet for each button. The optiongroup
property sheet can have a default value if you want.
 
my Q was return the OptionButton As Control
the .Value property tells me which OptionButton was clicked, but i need
that as a Control

using OptionGroup.Controls(x) is unreliable as a user may have changed
the order.

so is the option option to iterate the OptionGroup.Controls collection
to find the matching value?

riyaz
 
Riyaz,

Are you able to share with us *why* you want to do this?

One way would be to hard-code the names of the Option Buttons into a
Select Case statement similar to what Damon suggested.

I would probably make a table with two fields, and list the possible
Option Values and Names of the Option Buttons. Then code like this...
ControlName = DLookup("[ButtonName]","MyTable","[OptionValue]=" &
Me.MyOptionGroup)
 
I would be interested to know what your ultimate goal is for this. An option
button within the option group has little meaning as a control.
You can capture the name of the button with a little vba.
The OptionGroup control has a controls collection, so you could capture the
current value of the OptionGroup control, loop through its controls
collection until the control's OptionValue property is equal to the
OptionGroup value, then return the name of the control.
 
Are you able to share with us *why* you want to do this?

have unbound optiongroup (og) with optionbuttons (ob). selecting an ob
filters the form in some way. i've written a general procedure that
will filter when any ob is selected, the differences in the filter is
generated by what is contained in the tag of the ob selected. to get
the tag, i need the ob, which is why i asked if there is a quick way to
get the selected ob from the og.

this method makes my work easier, efficient, less error prone. the
necessary filtering is done declaratively by the string in the ob tag.
no code in the form module.

a Select Case statement is just to bulky for this case i think.
especially, when i deal with multiple forms using this same filter
(different forms may have different number of ob, in different order
too). i would go for iterating the og.Controls for ob until an ob with
correct value is found. then i have my ob.
 
Back
Top