title: Nested do ....while loops in access vba
body: <p>I am trying to run through all the records in an access table using nested do ...while loops.</p>
  
  <p>There is varying criteria for each loop so I am opening up multiple recordsets before I run the loops. </p>
  
  <p>When I run the code, it is working as it should, however the problem is when 1 of the recordsets has no records the whole process fails.</p>
  
  <p>Here is the bit of code for the nested loops.</p>
  
  <pre><code>    Dim rst1, rst2, rst3, rst4, rst5, rst6 As Recordset
  Dim sqlSt1, sqlSt2, sqlSt3, sqlSt4, sqlSt5, sqlSt6 As String
  Dim rcdCount, a, b, c, d, e, f As Double
  
  Set dbs = CurrentDb
  sqlSt1 = "SELECT * FROM [Rune List - Optimizer List] WHERE [Rune Slot]= 1"
  sqlSt2 = "SELECT * FROM [Rune List - Optimizer List] WHERE [Rune Slot]= 2"
  sqlSt3 = "SELECT * FROM [Rune List - Optimizer List] WHERE [Rune Slot]= 3"
  sqlSt4 = "SELECT * FROM [Rune List - Optimizer List] WHERE [Rune Slot]= 4"
  sqlSt5 = "SELECT * FROM [Rune List - Optimizer List] WHERE [Rune Slot]= 5"
  sqlSt6 = "SELECT * FROM [Rune List - Optimizer List] WHERE [Rune Slot]= 6"
  
  Set rst1 = dbs.OpenRecordset(sqlSt1)
  Set rst2 = dbs.OpenRecordset(sqlSt2)
  Set rst3 = dbs.OpenRecordset(sqlSt3)
  Set rst4 = dbs.OpenRecordset(sqlSt4)
  Set rst5 = dbs.OpenRecordset(sqlSt5)
  Set rst6 = dbs.OpenRecordset(sqlSt6)
  
  startTime = Time
  
  rcdCount = rst1.recordCount
  SysCmd acSysCmdInitMeter, "Processing: ", rcdCount
  
  Debug.Print "4: " &amp; rst4.recordCount
  Debug.Print "6: " &amp; rst6.recordCount
  
  
  Do While Not rst1.EOF And Not rst1.BOF
      Do While Not rst2.EOF And Not rst2.BOF
          Do While Not rst3.EOF And Not rst3.BOF
              Do While Not rst4.EOF And Not rst4.BOF
                  Do While Not rst5.EOF And Not rst5.BOF
                      Do While Not rst6.EOF And Not rst6.BOF
  
                          f = f + 1
                          rst6.MoveNext
                      Loop
  
                      e = e + 1
                      rst6.MoveFirst
                      rst5.MoveNext
                  Loop
  
                  d = d + 1
                  rst5.MoveFirst
                  rst4.MoveNext
              Loop
  
              c = c + 1
              rst4.MoveFirst
              rst3.MoveNext
          Loop
  
          b = b + 1
          rst3.MoveFirst
          rst2.MoveNext
      Loop
  
      a = a + 1
      SysCmd acSysCmdUpdateMeter, a
      DoEvents
  
      rst2.MoveFirst
      rst1.MoveNext
  Loop
  rst1.Close
  rst2.Close
  rst3.Close
  rst4.Close
  rst5.Close
  rst6.Close
  
  SysCmd acSysCmdRemoveMeter
  
  endTime = Time
  
  tmDuration = DateDiff("s", CDate(startTime), CDate(endTime))
  tm = Format(Int([tmDuration] / 3600), "00") &amp; ":" &amp; Format(Int(([tmDuration] - (Int([tmDuration] / 3600) * 3600)) / 60), "00") &amp; ":" &amp; Format((([tmDuration] Mod 60)), "00")
  
  Debug.Print a
  Debug.Print b
  Debug.Print c
  Debug.Print d
  Debug.Print e
  Debug.Print f
  Debug.Print "-----------------"
  Debug.Print tm
  </code></pre>
  
  <p>Is there an easy way I can check for empty records and skip the ones that will cause problems?</p>
  
  <p>Thanks for any help</p>
  
  <p>K</p>