Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to enable a bounch of controls in a frame 1

Status
Not open for further replies.

ii128

Programmer
May 18, 2001
129
US

Hi, does any one know how to enable a blunch of controls in a frame? following some codes doesn't work.

For Each ctl In Frame.Controls
If TypeOf ctl Is TextBox Then
ctl.Locked = False

End If
Next
 
A frame and inside has some text boxs
 
Did you declare ctl as Control? That's the only thing I see that would make that not work. Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
You can just disable/enable the frame, all child controls within the frame will be affected.
 
I don't think that is the problem because I have declared ctl as control.

It seems like it doesn't regonized Frame.controls

I mean the fram as fraTest

Dim ctl as control

For Each ctl In fraTest.Controls
If TypeOf ctl Is TextBox Then
ctl.Locked = False

End If
Next

After run, it pop up a compile error message "Method or data member or found" on Controls
 
Thanks jjame,

But I would like change the bgcolor of child controls within the frame. Any why I can do that?
 
There is no "frame" equivalent to Form.Controls. The best you can do is
Code:
    Dim ctl as control
    For Each ctl In form.Controls
        if ctl.Container is fratest
            On error resume next
                ctl.Locked = False                    
            On error goto 0         
        End If
   Next
 
This works:
'frame's name is Frame1
Option Explicit

Private Sub Command1_Click()
Dim ctl As Control

For Each ctl In Frame1.Container
If TypeOf ctl Is TextBox Then
ctl.Locked = True
End If
Next

End Sub
Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Mike.
For Each ctl In Frame1.Container
gets every control in the CONTAINER of Frame1 only if that container is the form. Try putting Frame1 inside another frame2 and you get "object doesn't support this property or meyhod". Only Form.Controls can be used to visit controls either explicitly as I did or implicitly as you did.
This blows up if frame1.container is another frame instead of the form.
Code:
Private Sub Form_Load()
    Dim obj As Control
    For Each obj In Frame1.Container
        Debug.Print obj.Name
    Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top