richh
Board Regular
- Joined
- Jun 24, 2007
- Messages
- 245
- Office Version
- 365
- 2016
Excel 2016 Windows 10
I'm trying to loop through all my controls on a user form to ensure they've been completed; I'm confused on how to check to see if one option button has been selected in a group of buttons. Each button is coupled with only one other button per group name, so if either one in the group is selected, that's acceptable. If both buttons aren't selected, then the user needs to go back and choose one.
I'm trying to loop through all my controls on a user form to ensure they've been completed; I'm confused on how to check to see if one option button has been selected in a group of buttons. Each button is coupled with only one other button per group name, so if either one in the group is selected, that's acceptable. If both buttons aren't selected, then the user needs to go back and choose one.
VBA Code:
Dim errString As String
Dim errFlag As Boolean
errString = ""
With Me
For Each cntrl In .Controls
If .Tag = "r" Then
Select Case TypeName(cntrl) = "OptionButton"
'Not sure how to check if one of the buttons in the group have been selected
Else
If Len(cntrl) = 0 Then
errFlag = True
errString = errString & cntrl.Name & vbNewLine
End If
End Select
End If
Next cntrl
If errFlag Then
MsgBox "The following required fields have been missed:" & vbNewLine & errString, vbCritical, "Please Complete the Form"
Exit Function
End if
End With