View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Susan Susan is offline
external usenet poster
 
Posts: 1,117
Default verify state of option button

there's another way somebody told me, once......
using frames to group each set of option buttons, you only have to check if
the # of frames with a true value are the same as the # of frames on your
userform! if 24 frames = true equals 24 frames total, then you know one
button (and only one) was selected in each frame.
this is the code i came up with from merjet............. it is JUST the
looping thru the frames to see if # matches. this is in my userform code.
=========================
Sub cmdEnter_click()

'make sure an option button is checked in each frame
i = 0

For Each oControl In Me.Controls
If TypeOf oControl Is msforms.OptionButton Then
If oControl Then
i = i + 1
End If
End If
Next
If i = 12 Then 'no. of frames
'do nothing
Else
MsgBox "Every frame must have a selected option button!" _
& vbCrLf & _
vbCrLf & _
"Please go back and answer all the questions." _
, vbOKOnly + vbExclamation
Exit Sub
End If

=======================
hope it helps!
susan







"stewart" wrote in message
oups.com...
I have a group of four option buttons on a userform. The user is
required to check select one of them. What can I put in my code to
verify this. What I currently have is below but it does not seem like
it is the most efficient way of completing this task as I have this
occurrence 34 separate times.


sub verify()
If opt1.Value = False And opt2.Value = False And opt3.Value = False
And opt4.Value = False Then
GoTo 2:
ElseIf opt5.Value = False And opt6.Value = False And opt7.Value =
False And opt8.Value = False Then
GoTo 2
end if

'other code below
...
exit sub
2: msgbox "Please verify that you have completed each section"
end sub