Public Sub EnableFrame(InFrame As Frame, ByVal Flag As
Dim Contrl As Control
'some controls don't have the Container.Name property, so instead of
'stopping the application with an error message, we ignore them.
On Error Resume Next
'enable or disable the frame that passed as parameter.
InFrame.Enabled = Flag
'passing over all controls
For Each Contrl In InFrame.Parent.Controls
'if the control is found in the frame
If (Contrl.Container.Name = InFrame.Name) Then
'if the control is a frame, and it's not the frame that passed as parameter, i.e.
'other frame that found inside our frame, recursively run this sub with this frame,
'to enable or disable all the controls in it.
If (TypeOf Contrl Is Frame) And Not (Contrl.Name = InFrame.Name) Then
EnableFrame Contrl, Flag
'enable or disable the control
If Not (TypeOf Contrl Is Menu) Then Contrl.Enabled = Flag
Private Sub Command1_Click()
EnableFrame Frame1, False
Private Sub Command2_Click()
EnableFrame Frame1, True