Solved

Excel userform option button / frames - retrieving value

Posted on 2012-04-02
3
2,156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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.

752 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