Solved

Excel userform option button / frames - retrieving value

Posted on 2012-04-02
3
1,536 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel Macro - Lookup-Highlight 4 25
Excel 2003 Conditional Formatting for Jan 1 3 13
Gantt chart 2 16
3rd level dependant list 4 27
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

760 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

17 Experts available now in Live!

Get 1:1 Help Now