Test a grouping of OptionButtons

  • Thread starter Patrick C. Simonds
  • Start date
P

Patrick C. Simonds

I have 4 OptionButton groups each group has a GroupName property set

Changed
Changed2
Changed3
Changed4

Is there any way to test a group and if all OptionButtons within that group
are false to display a message telling the user that they must select one of
the 6 options?
 
J

Joel

Try something like this

Sub test()

Set MyFrame = UserForm1.Frame1

Istrue = False
For Each but In MyFrame.Controls
If but.Value = True Then
Istrue = True
Exit For
End If
Next

If Istrue = False Then
MsgBox ("select a button in Frame 1")
End If

End Sub
 
P

Patrick C. Simonds

Is there any way to adjust that so that it checks each Group separately so
that I can display a different message for each group, so the user will know
which set of option buttons they need to look at?
 
P

Patrick C. Simonds

Thanks I figured it out

Patrick C. Simonds said:
Is there any way to adjust that so that it checks each Group separately so
that I can display a different message for each group, so the user will
know which set of option buttons they need to look at?
 
J

Joel

I would make the code a function like below. Change the MyFrame Array to
match all your frames.

Function FrameCheck() As Boolean

FrameError = False
MyFrames = Array("Frame1", "Frame2", "Frame3")
For Each FrmName In MyFrames
Set MyFrame = UserForm1.Controls(FrmName)
Itrue = False
For Each but In MyFrame.Controls
If but.Value = True Then
FrameError = True
Istrue = True
Exit For
End If
Next

If Istrue = False Then
MsgBox ("select a button in " & FrmName)
End If

Next FrmName

FrameCheck = FrameError
End Function
 

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

Top