title: How can a reference fields on an Access form using a variable?
body: <p>I have 20 text boxes on an Access 2010 form called [P101] to [P110] which refers to fields [P101] to [P110] in the source table.  The may contain a value or not, but if not I do not want to see them.  I also have a field [UsedFields] in the table which has counted how many of the fields are in use.  In Form_Current I can set the following code but is there a way I could set a FOR NEXT loop to use a variable for the Field Name?
  The current code (which works but is very clumsy) is:</p>
  
  <pre><code>If UsedFields &gt; 0 then
     P101.Visible = True
  Else
     P101.Visible = False
  End If
  If UsedFields &gt; 1 then
     P102.Visible = True
  Else
     P102.Visible = False
  End If
  .
  .  
  .
  .
  If UsedFields &gt; 9 then
     P110.Visible = True
  Else
     P110.Visible = False
  End If
  </code></pre>
  
  <p>As the number of fields is set to increase from 10 to 100 I would like to use a variable to hold the TextBox name, something like:</p>
  
  <pre><code>Private Sub Form_Current()
      Dim Ctrl As Control
      Dim CtrlName As String
      Dim Counter As Long
  
      For Counter = 1 To 10
          CtrlName = "P" &amp; Counter
          Set Ctrl = CtrlName
      If Counter &gt; Me.UsedFields Then
          Ctrl.Visible = False
      Else
          Ctrl.Visible = True
      End If
  End Sub
  </code></pre>
  
  <p>Is such a reference possible?</p>