ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Option buttons in two levels groups (https://www.excelbanter.com/excel-programming/418289-option-buttons-two-levels-groups.html)

Jac Tremblay[_4_]

Option buttons in two levels groups
 
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.
--
Jac Tremblay

Jac Tremblay[_4_]

Option buttons in two levels groups
 
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.

--
Jac Tremblay


"Jac Tremblay" wrote:

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.
--
Jac Tremblay



All times are GMT +1. The time now is 07:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com