title: VBA runtime error 3021 - No Current Record
body: <p>I am trying to export multiple datasets to the respective new Excel file.</p>
  
  <pre><code>   Public Sub MultipleQueries()
  
  Dim i As Integer
  Dim Mailer As Database
  Dim rs1 As Recordset
  Dim rs2 As Recordset
  Dim qdf As QueryDef
  
  Set Mailer = CurrentDb
  Set rs1 = Mailer.OpenRecordset("MailerData")
  Set qdf = Mailer.CreateQueryDef("CCspl", "PARAMETERS CostCentre Text ( 255 );SELECT MonthlyFteData.CostCentre, MonthlyFteData.EmpName, MonthlyFteData.Workload FROM MonthlyFteData WHERE (((MonthlyFteData.CostCentre)=[CostCentre]))")
  
  For i = 0 To rs1.RecordCount - 1
  
  qdf.Parameters("CostCentre") = rs1.Fields("CostCentre")
  
      Dim oExcel As Object
     Dim oBook As Object
     Dim oSheet As Object
     Set oExcel = CreateObject("Excel.Application")
     Set oBook = oExcel.Workbooks.Add
     Set oSheet = oBook.Worksheets(1)
  
  Set rs2 = qdf.OpenRecordset()
  
  With rs2
  
  oSheet.Range("A2").CopyFromRecordset rs2
  oBook.SaveAs "C:\Users\807140\Downloads\" &amp; rs2.Fields("CostCentre") &amp; ".xlsx"
  
  rs2.Close
  oExcel.Quit
  Set oExcel = Nothing
  
  End With
  
  rs1.MoveNext
  Next i
  
  qdf.Close
  Set qdf = Nothing
  rs1.Close
  
  End Sub
  </code></pre>
  
  <p>But I get the Runtime Error 3021 - No Current Record</p>
  
  <p>I substituted the</p>
  
  <pre><code>oSheet.Range("A2").CopyFromRecordset rs2
  oBook.SaveAs "C:\Users\807140\Downloads\" &amp; rs2.Fields("CostCentre") &amp; ".xlsx"
  </code></pre>
  
  <p>with </p>
  
  <pre><code>Debug.Print .RecordCount
  </code></pre>
  
  <p>And I do actually get the appropriate record count for rs2.</p>
  
  <p>How can I fix my code to eliminate the error?</p>