Check if a optionbutton is selected

  • Thread starter Thread starter Gert-Jan
  • Start date Start date
G

Gert-Jan

Hi,

In a userform I use three optionbuttons. One of them must be selected by the
user. How can let VBA check if this is done?

Regards, Gert-Jan
 
Hi Martin,

Thanks, but I know what I have to do. Isn't there a way to do this simple
and fast (not depending on the number of optionbuttons)?

Gert-Jan
 
maybe something like this, change userform1 to your userform name

Dim optionbuttom As Control
For Each OptionButton In UserForm1.Controls
If OptionButton.Value = True Then
MsgBox OptionButton.Caption & " = True"
End If
Next
 
sorry, there is a typo in the first line:
Dim Optionbutton As Control
 
I don't believe that the group or frame properties allow for the
identificaiton of the option button that is true.

The solution is to write a generic function that returns the name to the
optionbutton that is true in a group.

Not much help.
 
I see what you want to do, but this is not what I want (and it also doesn't
work). In my userform I have three option buttons. Final operation: check if
one of the optionbuttons is clicked. If not: msgbox "please select an option
first"

Gert-Jan
 
if you only have 3 option buttons:

If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False And _
Me.OptionButton3.Value = False Then MsgBox " you must select an option
button"
 
if OptionButton1.Value or OptionButton2.Value or _
OptionButton3.Value then
' one button is selected
else
msgbox "please select an option first"
end if
 
or how about something like this? just add your code instead of the message
boxes

Private Sub CommandButton1_Click()
Select Case True
Case Me.OptionButton1
MsgBox "optionbutton1 selected"
Case Me.OptionButton2
MsgBox "optionbutton2 selected"
Case Me.OptionButton3
MsgBox "optionbutton3 selected"
Case Else
MsgBox "no optionbutton selected"
End Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top