Object Array

  • Thread starter Thread starter Phill
  • Start date Start date
P

Phill

is it possible to create an array of objects.

Eg.

lets say i have 50 textboxes on a form all with the same
name and numbered from 1 to 50.

eg. Textbox1, Textbox2 ... Textbox50

I need to access them individually to run code that makes
them all invisible bar 1 at a certain point.

I'm trying to use the following code although its not
working because it doesn't recognise the object.

For MyTextNumber = 1 to 50
Textbox(MyTextNumber).visible = false
Next

I've also tried
Textbox & MyTextNumber.visible = false

is there anyway object names can be broken into a basename
and variable to work with.

any help would be gratefully appreciated!

thanks

Phill
 
Phill,

Change your code as follows:

For MyTextNumber = 1 to 50
Forms("FormNameHere").Controls("Textbox" & MyTextNumber).visible = false
Next

substituting FormNameHere with your actual form name.
HTH,
Nikos
 
Hi Phil,

This will give you what you need

Dim i As Integer
For i = 1 To 50
Me("Textbox" & i).Visible = False
Next i

HTH
Steve C
 
Back
Top