Results 1 to 4 of 4

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

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    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
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    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

  3. #3
    New Member
    Join Date
    Oct 2016
    Posts
    1

    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.

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,910

    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.

    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
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Posting Permissions

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



Click Here to Expand Forum to Full Width