Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Userforms Textbox control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
elizabeth.cornelius@gmail.com - 07 Feb 2007 01:17 GMT
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**********************
Jay Freedman - 07 Feb 2007 02:00 GMT
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.

>Hi Guys
>
[quoted text clipped - 28 lines]
>
>*******************END CDE**********************
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.