Option buttons in two levels groups

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.
 
J

Jac Tremblay

Hi, it's me...
I found a simple solution. In a separate procedure where I hide all the
subgroups before I display the one selected, I added some code to deselect
all options. It goes like that and works fine.
Dim ctrOb As Control
For Each ctrOb In Controls
If TypeOf ctrOb Is msforms.OptionButton Then
If ctrOb.GroupName <> "grpCompte" Then
If ctrOb.Value = True Then ctrOb.Value = False
End If
End If
Next
I was inspired by Rick and Dave. Thanks to them.
I thought I posted this for the benefit of the community.
Good night to everyone.
 

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