title: Access 2010 VBA ControlSource Loop
body: <p>I have multiple fields on a form that have no values associated with them until data is entered into that field. At which point those controls have the <strong>#Name?</strong> value. All I'm trying to do is hide the fields using a loop as opposed to writing If statements. Here is the code working with a single If statement to hide said field/fields.</p>
  
  <pre><code>If Not Me.txtField.ControlSource = "#Name?" Then
     Me.txtField.ColumnHidden = True
  End If
  </code></pre>
  
  <p>I can't seem to figure out how to hide multiple controls that have the #Name? flag. Any help would be appreciated.</p>
  
  <pre><code>Dim ctl As Control
  Dim ctlError As String
  
  ctlError = "#Name?"
  
   For Each ctl In Me.Controls
       If Not ctl.ItemsSelected(txtField) = ctlError Then
            ctl.ColumnHidden = True
       End If
   Next ctl
  </code></pre>
  
  <p>EDIT:
  On the main form there is a subform with a cross tab query. But the problem is results on the query are populated from a combobox. So I've added fields that are not yet available in the query to the subform and end up with #Name? Attached is a screenshot to better illustrate the issue.</p>
  
  <p>There is a 90% chance I'm going about this process wrong, so it's a learning process right now.</p>
  
  <p><img src="https://i.stack.imgur.com/OnZ9Y.jpg" alt="ScreenShot"></p>