Solved

Excel userform option button / frames - retrieving value

Posted on 2012-04-02
3
2,035 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 42

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

685 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