CodeItBetter Programming Another VB Programming Blog

How to Enable/Disable all Controls in a frame

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'Controls - How to Enable/Disable all Controls in a frame

Option Explicit
 
'Insert a Frame and two Command Buttons to your form.
'Insert some controls to the frame.

Public Sub EnableFrame(InFrame As Frame, ByVal Flag As Boolean)
    Dim ctl As Control
    On Error Resume Next
    InFrame.Enabled = Flag
    For Each ctl In InFrame.Parent.Controls
        If (ctl.Container.Name = InFrame.Name) Then
            If (TypeOf ctl Is Frame) And Not (ctl.Name = InFrame.Name) Then
                EnableFrame ctl, Flag
            Else
                If Not (TypeOf ctl Is Menu) Then ctl.Enabled = Flag
            End If
        End If
    Next
End Sub
 
'How can I call this function:
Private Sub Command1_Click()
    'To disable all controls in a frame
    EnableFrame Frame1, False
End Sub
 
Private Sub Command2_Click()
    'To enable all controls in a frame
    EnableFrame Frame1, True
End Sub
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.