title: Microsoft Access 2010 Memory Leak DAO recordset and RUNSQL
body: <p>My problem is, with each iteration of an update loop, I lose about 100k of memory, so eventually, I get an out of resource error after a few thousand iterations.</p>
  
  <p>The question is, why am I losing memory?</p>
  
  <p>Below is a code fragment which is a loop updating data.</p>
  
  <p>The criteria is extracted from a local database, dao.recordset method. -- rs1</p>
  
  <p>The comparison comes from the target database where the update will be done, dao.recordset method.  -- rs2 is the target read to see if I need to do an update</p>
  
  <p>The update is a Docmd.Runsql query into a linked sharepoint table.   And yes, I know I could use .edit and .update but in that case other strange things happen for a different post.  :)</p>
  
  <p>Access 2010 into Sharepoint 2010</p>
  
  <pre><code>Dim db As DAO.Database
  Dim rs1 As DAO.Recordset
  Dim rs2 As DAO.Recordset
  
  Set db = CurrentDb
  Set rs1 = db.OpenRecordset("datefix")
  
  Do While Not rs1.EOF
      Set rs2 = db.OpenRecordset("select `Required delivery` from xyzzy where `SO Line` = '" &amp; rs1.Fields(0).Value &amp; "'")
      If rs1.Fields(1).Value = rs2.Fields("Required delivery") Then
      Else
          DoCmd.RunSQL "update ProblemTracking set `Required delivery` = '" &amp; rs1.Fields(1).Value &amp; "', `1st GI Dat` = '" &amp; rs1.Fields(2).Value &amp; "' where `SO Line` = '" &amp; rs1.Fields(0).Value &amp; "'"
      End If
      rs2.Close
      Set rs2 = Nothing
  
      rs1.MoveNext
  Loop
  </code></pre>