Results 1 to 4 of 4

Thread: Collection, container, controls?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Hey there. I'd need professional help =) I'm trying to create a collection with all the controls (mainly textboxes) that I will specify. After this is done, I will loop though the collection and set these controls to .visible = False. That means I need to refer to them.

    I tried reading the help topic on collections, containers, containedcontrols, vbcontrols and some other topics and couldn't find any way of doing this by myself. So here I am.

    Thanks for the help.

    (If I cannot do this, I thought I could simply add the control names to a collection or an array, but then is there any way of using that string, ex.: "txtMyControl", and referencing to it?)

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    This is the code behind a command button for an example where there are three Textboxes on a form. When the command button is clicked, the forecolor of the objects in the collection change.
    Code:
    Private Sub Command1_Click()
    
    Dim MyCollection As New Collection
    Dim nCount As Integer
    
    MyCollection.Add Text1
    MyCollection.Add Text3
    
    For nCount = 1 To MyCollection.Count
        MyCollection.Item(nCount).ForeColor = vbRed
    Next nCount
    
    End Sub
    A word of caution. You can add anything to a collection, like a vertical scrollbar that desn't have a forecolor property. Doing that will yield an error when you run through the loop.

    ------------------
    Marty

  3. #3
    Junior Member
    Join Date
    Nov 1999
    Posts
    21

    Post

    Dim c As Object
    For Each c In Form1
    If TypeOf c Is TextBox Then
    c.Visible = False
    End If
    Next c

    I hope this is what u want.


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    This works well, thanks!

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