title: Why can't I get textbox.text values from code generated textboxes
body: <p>I have a project where I have a form "userform1" which only has a "GO" button and an "EXIT" button on it to begin with. I solicit user input via an inputbox for a number. I use code to then populate the form with that number of labels and textboxes and display the form to allow editting of the created textboxes. Everything works fine up to this point.
  I then want the "GO" button to populate an array with the textbox.text values for use elsewhere. This is where I am having a problem.</p>
  
  <p>I tried retrieving the text like I normally do (something like; Xstring = UserForm1.Box1.Text), that didn't work. So then I cycled thru the form controls; UserForm1.Controls.index(), looking for my Textbox .names to confirm they existed. I found them, so I singled one out, index(3), .name = "Box1".  See below: </p>
  
  <pre><code>Dim tText As String
  tText = UserForm1.Box1.Text
  MsgBox tText
  </code></pre>
  
  <p>returns an ERROR, 'method or data member not found'</p>
  
  <p>But if I change it to this:</p>
  
  <pre><code>Dim x As Object
  Dim tText As String
  Set x = UserForm1.Controls.Item(3)
  tText = x.Text
  MsgBox tText
  </code></pre>
  
  <p>The msgbox returns the .text value</p>
  
  <p>So, QUESTION is, why can't I simply address it normally? I don't want to have to go through all the extra steps to figure out index numbers vs names to populate my array. </p>
  
  <p>for reference, below is partial code of my sub for creating labels/textboxes:</p>
  
  <pre><code>For i = Data(x, 1) To z
      Lab = "forms.label.1"
      Box = "forms.textbox.1"
      Set newlabel = UserForm1.Controls.Add(Lab)
      Set newtextbox = UserForm1.Controls.Add(Box)
      lbl1 = ("Label" + CStr(i))
      With newlabel
          .Name = lbl1
          .Caption = "No. " + CStr(i)
          .Left = Data(x, 3)
          .top = top
          .Height = 20
          .Width = 30
      End With
      lbl2 = ("Box" + CStr(i))
      With newtextbox
          .Name = lbl2
          .Text = CStr(i)
          .Left = (Data(x, 3) + 35)
          .top = top
          .Height = 20
          .Width = 36
      End With
      top = top + 25
  Next i
  </code></pre>