OptionButton & CheckBox

Hello Experts,

I have added a few OptionButton's & CheckBoxes to my UserForm in Outlook - but they're different then dropdown boxes (which I am familiar with).  I am hoping for someone to post example VBA code, showing me how I interact with an OptionButton & Checkbox - and store the values in variables.

Example:

OptionButton = Choices "Yes" & "No".

I assume one variable, would hold the answer to the OptionButton.

CheckBoxes = "Apple" & "Bread" & "Cheese"

And I assume CheckBoxes would involve multiple variables?

I'm pretty confused.

Thank you in advance for your help!

~ Geekamo
LVL 1
GeekamoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
Each option button and each check box has a Value property which can be either True or False.

The difference is that in when an option button is clicked, automatically, one and only one of the buttons in the group is set to True. Check boxes are independent of each other.

If you wanted to return string values, you would have to write code to examine the Value properties. Here are two illustrative functions.
Function OptionButtons() As String
    If OptionButton1.Value Then
        OptionButtons = "First"
    End If
    If OptionButton2.Value Then
        OptionButtons = "Second"
    End If
    '...
End Function

Function CheckBoxes() As String
    If CheckBox1.Value Then
        CheckBoxes = "First"
    End If
    If CheckBox2.Value Then
        CheckBoxes = CheckBoxes & " Second"
    End If
    '...
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArkCommented:
Enterprise edition :)
Function OptionButtons(container As Object) As String
   Dim ctrl As Control
   OptionButtons = "Nothing"
   For Each ctrl In container.Controls
      If TypeOf ctrl Is MSForms.OptionButton Then
         If ctrl.Value = True Then
            OptionButtons = ctrl.Caption
            Exit For
         End If
      End If
   Next
End Function

Function CheckBoxes(container As Object) As String
   Dim ctrl As Control, s As String
   For Each ctrl In container.Controls
      If TypeOf ctrl Is MSForms.CheckBox Then
         If ctrl.Value = True Then
            If s <> "" Then s = s & " + "
            s = s & ctrl.Caption
         End If
      End If
   Next
   If s = "" Then s = "Nothing"
   CheckBoxes = s
End Function

Open in new window

Call:
MsgBox CheckBoxes(Me)
MsgBox OptionButtons(Frame1)
0
Martin LissOlder than dirtCommented:
And normally Option Buttons (which are also called radio Buttons) are used to present the user which a small number of mutually exclusive choices. I say a small number because if there more than two or three, a listbox or combobox is the normal solution. Checkboxes on the other hand are used to present the user with a small number of non-mutually exclusive choices but again if there's more than a few, a listbox or combobox is the normal solution.
0
ArkCommented:
...with a small number...
prooflink :)
0
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.