title: Can I use a variable as the name of a control in Microsoft Access VBA
body: <p>I have a Microsoft Access Popup Form which I use to lookup addresses. Once the user has found the postcode, the address is then put into various text boxes on the form it was launched from. The problem is, this popup form is launched from various forms throughout the database and so the text boxes it puts the result into are in different locations.</p>
  
  <p>I tried to work around this in the following way. I have a switchboard which is open at all times so I have a hidden Textbox on there which I programmatically put the name of the form I am launching the popup form from. I then declare a string variable which is set to the current value of this hidden textbox like so:</p>
  
  <pre><code>Dim currentForm As String
  currentForm = [Forms]![foo]![bar]
  </code></pre>
  
  <p>I then tried to put my address details into the relevant textboxes like so:</p>
  
  <pre><code>Forms!currentForm![txtCurrentAdd1] = rst![Line1]
  </code></pre>
  
  <p>However this isn't working as planned, what am I doing wrong?</p>
  
  <p>Thanks</p>