J
Jac Tremblay
Hi,
I have about 50 options buttons that are grouped in 8 main groups accessible
through 8 main level option buttons. Once a main level option button is
selected, a sub level group appears (the other ones become invisible) for the
user to select a sub level option. There is a default option on both levels
so that there is always a selection in both levels. I need to find the sub
level option button that is selected to continue the process.
I came upon this code from Rick Rothstein (commented by Dave Peterson) and
adapted it to suit my case but I always get options from the first subgroup.
The last one selected remains the one that will come out. I cannot get any of
the others even though they are visible and selected. What could be the
problem?
Here is the code:
Dim ctrOb As Control
Dim ctrObSelected As msforms.OptionButton
' On Error Resume Next
For Each ctrOb In Controls
If TypeOf ctrOb Is msforms.OptionButton Then
If ctrOb.GroupName <> "grpCompte" And _
ctrOb.GroupName <> "grpDrpTypeTransac" And _
ctrOb.GroupName <> "grpDrpTransfert" And _
ctrOb.GroupName <> "grpTypeTransac" Then
If ctrOb.Value = True Then
Set ctrObSelected = ctrOb
Exit For
End If
End If
End If
Next
If Err.Number > 0 Then
MsgBox "No OptionButton selected"
Else
MsgBox "ctrObSelected.Name = " & ctrObSelected.Name & _
vbCrLf & "ctrObSelected.Caption = " & ctrObSelected.Caption
End If
Thank you.
I have about 50 options buttons that are grouped in 8 main groups accessible
through 8 main level option buttons. Once a main level option button is
selected, a sub level group appears (the other ones become invisible) for the
user to select a sub level option. There is a default option on both levels
so that there is always a selection in both levels. I need to find the sub
level option button that is selected to continue the process.
I came upon this code from Rick Rothstein (commented by Dave Peterson) and
adapted it to suit my case but I always get options from the first subgroup.
The last one selected remains the one that will come out. I cannot get any of
the others even though they are visible and selected. What could be the
problem?
Here is the code:
Dim ctrOb As Control
Dim ctrObSelected As msforms.OptionButton
' On Error Resume Next
For Each ctrOb In Controls
If TypeOf ctrOb Is msforms.OptionButton Then
If ctrOb.GroupName <> "grpCompte" And _
ctrOb.GroupName <> "grpDrpTypeTransac" And _
ctrOb.GroupName <> "grpDrpTransfert" And _
ctrOb.GroupName <> "grpTypeTransac" Then
If ctrOb.Value = True Then
Set ctrObSelected = ctrOb
Exit For
End If
End If
End If
Next
If Err.Number > 0 Then
MsgBox "No OptionButton selected"
Else
MsgBox "ctrObSelected.Name = " & ctrObSelected.Name & _
vbCrLf & "ctrObSelected.Caption = " & ctrObSelected.Caption
End If
Thank you.