Results 1 to 2 of 2

Thread: VB Snippet - Enable all Controls within a Frame Control

  1. #1
    PowerPoster
    Join Date
    Aug 00
    Location
    IN SILENCE
    Posts
    6,441

    VB Snippet - Enable all Controls within a Frame Control

    VB Code:
    1. Public Sub EnableFrame(InFrame As Frame, ByVal Flag As Boolean)
    2.  
    3.     Dim Contrl As Control
    4.  
    5.     On Error Resume Next 'not all controls have a container property
    6.  
    7.     InFrame.Enabled = Flag
    8.  
    9.     For Each Contrl In InFrame.Parent.Controls
    10.  
    11.         If Contrl.Container.Name = InFrame.Name Then
    12.  
    13.             If (TypeOf Contrl Is Frame) And Not (Contrl.Name = InFrame.Name) Then
    14.  
    15.                 EnableFrame Contrl, Flag 'repeat for nested frame
    16.  
    17.             Else
    18.  
    19.                 Contrl.Enabled = Flag
    20.  
    21.             End If
    22.  
    23.         End If
    24.  
    25.     Next
    26.  
    27. End Sub
    28.  
    29. Private Sub Command1_Click()
    30.  
    31.     EnableFrame frame1,True
    32.  
    33. End Sub
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    Addicted Member
    Join Date
    Dec 09
    Posts
    197

    Lightbulb 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •