title: Access 2013: Reference with variables to an object with VBA
body: <p>I'm trying to make a loop with VBA and check for different Access fields (named "Areas") if they are True or False.</p>
  
  <p>If three Areas are True, my Sub should return their names (i.e. "AreaA, AreaF, AreaG").</p>
  
  <p>The problem is, I'm getting an error: "<strong>Compile error. Type Mismatch.</strong>" in the line shown below and the second "<strong>&amp;</strong>" is highlighted.</p>
  
  <pre><code>Set chkObject = "[Forms]![1110 Datos]![Area_" &amp; Area(i) &amp; "]"
  </code></pre>
  
  <p>These are some existent objects (checkboxes):</p>
  
  <p><strong>[Forms]![1110 Datos]![Area_Cnc]</strong></p>
  
  <p><strong>[Forms]![1110 Datos]![Area_Emb]</strong></p>
  
  <p><strong>[Forms]![1110 Datos]![Area_Ens]</strong></p>
  
  <p>Here's my code:</p>
  
  <pre><code>Sub MySub()
  Dim Area() As String, Vars As String, i As Integer, chkObject As Object
  Dim strAreas As String
  Vars = "Cnc, Emb, Ens, Esp, Fer, For, Maq, Pin, Pon, Sie, Sol, Tel, Rou"
  
  Area = Split(Vars, ", ")
  strAreas = "" 'Set blank.
  
  For i = 0 To UBound(Area)
      Set chkObject = "[Forms]![1110 Datos]![Area_" &amp; Area(i) &amp; "]" 'Reference to the Object.
  
      If chkObject.Value = True Then
          If strAreas = "" Then 'Check if it is the first Area: "Cnc" OR "Esp"...
              strAreas = Area(i)
          Else
              strAreas = strAreas &amp; ", " &amp; Area(i) 'To add commas if already exists one checked: "Cnc, Esp, Sie"
          End If
      End If
  
  If strAreas = "" Then 'If no Areas were checked...
      Debug.Print "Ningún area estaba activa."
  Else
      Debug.Print strAreas 'Else, return selected Areas
  End If
  
  Next
  End Sub
  </code></pre>
  
  <p>Does anyone know how to reference this?</p>
  
  <p>Thanks in advance!!</p>