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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting to know the names or tags of all the controls in a frame 1

Status
Not open for further replies.

BasicBoy

Programmer
Feb 22, 2008
156
ZA
I have an application where I need to identify all the controls which have been placed in a certain frame control, and then iterate through them and see which are visible.

Thanks
 
Each form has a controls array, and each control has a container. You can iterate through all the controls on the form and search for those within in certain container, and then look at the visible property. Something like this....

Code:
    Dim oControl As Control

    For Each oControl In Me.Controls
        If oControl.Container.Name = YourName.Name Then
            If oControl.Visible Then
                Debug.Print oControl.Name
            End If
        End If
    Next

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you - can you just elaborate on Yourname.name - what I should put in there

Thanks
 
Replace YourName with the name of the frame you want to check. For example, I created a new vb app. I put a frame on the form and left it the default name (Frame1). In this case, change "YourName" to "Frame1".

Does this make sense?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I thought that I have to put two names in that one variable. Thanks
 
I have fraSearch or fraSearch.name and it says it does not support that operation
 
try this...

Code:
    Dim oControl As Control

    For Each oControl In Me.Controls
        If oControl.Container.Name = fraSearch.Name Then
            If oControl.Visible Then
                Debug.Print oControl.Name
            End If
        End If
    Next

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
That is what I had - it gives me error 438 - Object does not support this property or method. The fraSearch.name I can see it understand, but it has a problem with the part before the =
 
I see. The problem is that not all controls have a container property, which is causing your error message. Some controls are "hidden" like a timer control. There is nothing to see, so there is no container for it.

You can handle this by using error handling, like this:

Code:
    On Error GoTo NoContainer
    
    For Each oControl In Me.Controls
        If oControl.Container.Name = fraSearch.Name Then
            If oControl.Visible Then
                Debug.Print oControl.Name
            End If
        End If
NoContainer:
    Next

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I thought that that was the problem. Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top