title: Execute my query in VBA Access while looping
body: <p>I am getting an error when I try to execute my query in my loop.<br>
  What I try to do is to loop through my recordset and return the value matching the ID. I have a table named Manufacturer and 2 columns named ID and Manuf.<br>
  I have commented out the 3 different execution methods, as I cannot get them to work probably.</p>
  
  <pre><code>Sub LoopExample()
  On Error GoTo Error_Handler
  Dim db              As DAO.Database
  Dim rs              As DAO.Recordset
  Dim iCount          As Integer
  Dim strSQL          As String
  Dim intManu         As Integer
  
  strSQL = "SELECT * FROM Manufacturer"
  
  Set db = CurrentDb()
  Set rs = db.OpenRecordset(strSQL) 'open the recordset for use (table, Query, SQL Statement)
  
          Do While Not rs.EOF
  
              intManu = rs!ID
              strSQL = "SELECT Manuf FROM Manufacturer WHERE CustomerID='" &amp; intManu &amp; "'"
  
              'db.Execute (strSQL), dbFailOnError
              'DoCmd.OpenQuery strSQL, acViewNormal
              'CurrentDb.OpenRecordset (strSQL)
              Debug.Print strSQL
  
          rs.MoveNext
          Loop
  
  
  rs.Close 'Close the recordset
  
  Error_Handler_Exit:
  On Error Resume Next
  'Cleanup after ourselves
  Set rs = Nothing
  Set db = Nothing
  Exit Sub
  
  Error_Handler:
  MsgBox "MS Access has generated the following error" &amp; vbCrLf &amp; vbCrLf &amp; "Error Number: " &amp; _
  Err.Number &amp; vbCrLf &amp; "Error Source: LoopRecExample" &amp; vbCrLf &amp; "Error Description: " &amp; _
  Err.Description, vbCritical, "An Error has Occured!"
  Resume Error_Handler_Exit
  End Sub
  </code></pre>