title: word vba macro - dynamically reference form elements
body: <p>I have a userform that I have created that contains a number of TextBoxes. Each of these fields are named name1, name2, name3, etc.</p>
  
  <p>This userform is called from a Word macro used to process data. Depending on the data in the file the macro is run on, I want content from an array to be displayed in each of those TextBoxes. </p>
  
  <p>What I want to be able to do is dynamically reference the form TextBoxes so that I can populate them from within a loop, as opposed to having to do a separate if statement for each individual value/TextBox.</p>
  
  <p>So for example, instead of having to do something like this:</p>
  
  <pre><code>For p = 1 To count
     if p=1 then
         dForm.name1.Text=myVar(p)
     end if
     if p=2 then
         dForm.name2.Text=myVar(p)
     end if
     .
     .
     .
     etc.
  Next p
  </code></pre>
  
  <p>I want to be able to something much more simple and efficient like:</p>
  
  <pre><code>For p = 1 To count
     tempString = "name" &amp; p
     dForm.tempString.Text = myVar(p)
  Next p
  </code></pre>
  
  <p>Unforunately though, I cannot figure out how to do this.</p>
  
  <p>Is this possible? I had been hoping that something similar to what can be done in Actionscript would work, but it didn't (in Actionscript I would simply just do dForm["name"+p].Text = myVar[p]).</p>
  
  <p>Any ideas/suggestions? Nothing I've tried has worked, and I haven't been able to find anything online about this. I'm sure there has got to be some work around to avoid having to do an incredible number of if statements (the 'name' TextBoxes' is just one of many repeating TextBoxes that is part of my form, so having to do if statements for all of them would take forever) ...</p>