Public ufEventsDisabled As Boolean
Dim CPOptionButtons As Collection
Private Sub UserForm_Initialize()
Dim oneControl As Object
Dim oneCPOptionButton As clsCrossParentOptionButton
Set CPOptionButtons = New Collection
For Each oneControl In Me.Controls
If TypeName(oneControl) = "OptionButton" Then
Set oneCPOptionButton = New clsCrossParentOptionButton
Set oneCPOptionButton.CPOptionButton = oneControl
CPOptionButtons.Add oneCPOptionButton, Key:=oneControl.Name
End If
Next oneControl
Set oneCPOptionButton = Nothing
End Sub
Private Sub UserForm_Terminate()
Dim oneCPOptionButton As clsCrossParentOptionButton
For Each oneCPOptionButton In CPOptionButtons
Set oneCPOptionButton = Nothing
Next oneCPOptionButton
Set CPOptionButtons = Nothing
End Sub
'Create this class first
Public WithEvents CPOptionButton As MSForms.OptionButton
Private Sub cpOptionButton_Change()
Dim myUF As Object
Dim oneControl As MSForms.Control
Set myUF = Me.ParentUF
If myUF.ufEventsDisabled Then Exit Sub
myUF.ufEventsDisabled = True
For Each oneControl In myUF.Controls
With oneControl
If TypeName(oneControl) = "OptionButton" Then
If oneControl.GroupName = CPOptionButton.GroupName Then
.Value = (.Value And (.Parent.Name = CPOptionButton.Parent.Name))
End If
End If
End With
Next oneControl
myUF.ufEventsDisabled = False
End Sub
Property Get ParentUF() As Object
Set ParentUF = CPOptionButton.Parent
On Error Resume Next
Do
Set ParentUF = ParentUF.Parent
Loop Until Err
On Error GoTo 0
End Property