Jay
Tue Feb 06 20:00:09 CST 2007
Regardless of what you may think you put into the array myTest, what
you actually have is an array of strings stored in a Variant. You know
that those strings are the names of text boxes in the userform, but
VBA doesn't know how to figure that out. :-)
The userform does have a Controls collection that contains all the
controls (text boxes, buttons, combo boxes, etc.). That collection has
a .Item method that takes either an index number or the name as a
string, and returns the corresponding control. So you can use
UserForm1.Controls.Item(myTest(i)) = myTest1(i)
and it will work. As a short of shorthand, you can write the same
thing as
UserForm1.Controls(myTest(i)) = myTest1(i)
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On 6 Feb 2007 17:17:47 -0800, elizabeth.cornelius@gmail.com wrote:
>Hi Guys
>
>I am trying to use an array to select various textboxes on a userform
>but keep getting an error when compiling the code saying 'Method or
>data member not found'. I understand the essage but cannot work out
>how to overcome it.
>
>Here is the code, it is pretty simple as it is just trying to sort out
>the code.
>
>Thanks
>
>Damon & Elizabeth
>
>****************CODE****************
>
>Private Sub CommandButton1_Click()
>
>Dim myTest, myTest1
>Dim i As Integer
>
>
>myTest = Array("txt1", "txt2")
>myTest1 = Array("Goodbye", "So long", "Adiue")
>
>For i = LBound(myTest) To UBound(myTest)
>
> UserForm1.myTest(i) = myTest1(i)
>
>Next i
>End Sub
>
>*******************END CDE**********************