Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel userform option button / frames - retrieving value

Posted on 2012-04-02
3
Medium Priority
?
3,218 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

773 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