PDA

Click to See Complete Forum and Search --> : Collection, container, controls?


David Laplante
Nov 10th, 1999, 09:16 PM
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?)

MartinLiss
Nov 10th, 1999, 10:26 PM
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.
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

shan1
Nov 10th, 1999, 10:31 PM
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.

David Laplante
Nov 10th, 1999, 10:48 PM
This works well, thanks!