Solved

Excel userform option button / frames - retrieving value

Posted on 2012-04-02
3
1,659 Views
Last Modified: 2012-06-21
Hello,

i would like to understand how to know which option button has been chosen in an option group (frame) on my form.
Userform.

How can I find the value, or, which radio button has been selected ?
I have tried me.frame2.blah.... but I can't see a property in the frame2 collection referring to which option/radio button has been selected.

Any help is appreciated.

Thanks,

Craig
0
Comment
Question by:slobber72
  • 2
3 Comments
 

Author Comment

by:slobber72
ID: 37799042
Hi again,

I have created the following function to get the value of the option button selected.

Is this the proper way to get this info ?

Private Function get_comment_type(ByVal comment_frame As frame)

Dim o As Control
Dim comment_type As String

For Each o In comment_frame.Controls
    If o.Value = True Then
        comment_type = o.Caption
        Exit For
    End If
Next o

get_comment_type = comment_type

End Function

Open in new window


It works quite well - but I was wondering if it is needed, or if it is accessible directly from the frame object.

Cheers,

Craig
0
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 37799093
If you want to get the value of an option button at the TIME OF SELECTION, just use the related click event, e.g.,

Private Sub OptionButton1_Click()
   'your code goes here to test the value of the option button
   myVal = Me.OptionButton1.Value
End Sub

Open in new window


Otherwise, you DO need to iterate through all the controls in the frame to determine which is true, though you need to differentiate between an option button and a checkbox, in case there are check boxes also in the frame, correct? Also, you don't want to test other values of other controls that might be in the frame other than the option button (e.g., perhaps a text box, or combo box, etc., so its best to ascertain that the control you're testing is indeed an option button first).

Private Function get_comment_type(ByVal comment_frame As Frame)

Dim o As Control
Dim comment_type As String

For Each o In comment_frame.Controls
    If o.DisplayStyle = fmDisplayStyleOptionButton Then
        If o.Value = True Then
            comment_type = o.Caption
            Exit For
        End If
    End If
Next o

get_comment_type = comment_type

End Function

Open in new window




Dave
0
 

Author Closing Comment

by:slobber72
ID: 37799120
Terrific - again !!
Thanks Dave.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now