VB Snippet - Enable all Controls within a Frame Control
VB Code:
Public Sub EnableFrame(InFrame As Frame, ByVal Flag As Boolean)
Dim Contrl As Control
On Error Resume Next 'not all controls have a container property
InFrame.Enabled = Flag
For Each Contrl In InFrame.Parent.Controls
If Contrl.Container.Name = InFrame.Name Then
If (TypeOf Contrl Is Frame) And Not (Contrl.Name = InFrame.Name) Then
EnableFrame Contrl, Flag 'repeat for nested frame
Else
Contrl.Enabled = Flag
End If
End If
Next
End Sub
Private Sub Command1_Click()
EnableFrame frame1,True
End Sub
Re: VB Snippet - Enable all Controls within a Frame Control
hi, i m very sorry to say. but your code has a bug/error.. because as you used resume next, it also handle unwanted (not a child control of specific frame) that user may not want..
so, the following code only handle (disable/enable) the controls that parent is the frame.
Code:
Public Sub sEnableFrame(objFrame As Frame, ByVal bolFlag As Boolean)
On Error GoTo mahabub_S1Error
Dim objControl As Control
objFrame.Enabled = bolFlag
For Each objControl In Me.Controls
If objControl.Container.Name = objFrame.Name Then
If (TypeOf objControl Is Frame) Then
sEnableFrame objControl, bolFlag
Else
objControl.Enabled = bolFlag
End If
End If
mahabub_nextS1Loop:
Next objControl
Set objControl = Nothing
Exit Sub
mahabub_S1Error:
If Err.Number = 438 Then
Resume mahabub_nextS1Loop
Exit Sub
End If
End Sub
however thanks for the idea..
best regards
Re: VB Snippet - Enable all Controls within a Frame Control
Thanks @Shohag_ifas. Your alternate solution worked great on the app that I'm developing.
Re: VB Snippet - Enable all Controls within a Frame Control
What about a PictureBox on the frame with further nested control, or possibly an SSTab control on the frame. :p
Here's one that works regardless of the type of container you're digging down into:
http://www.vbforums.com/showthread.p...=1#post5084349
Enjoy,
Elroy