title: Access VBA Loop through Query help
body: <p>I have a form (Cobind_frmMain) that allows the user to create a pool of titles that are attached to it. So there is a top level Pool Name (TopLvlPoolName) and on a subform, the titles are added to it. What I need is to issue a Report for each of the titles. I have the report and queries all set up. Right now, the report will show all the titles in one file. The titles are in a field called "CatCode". </p>
  
  <p>What I need is the following:<br>
  1. Save each title as a PDF and save it to our server.<br>
  2. Open email and attach the PDF.<br>
  3. Repeat until all titles are done.  </p>
  
  <p><strong>EDIT:</strong> This is what I have so far for code and the error message I still get is: "Too Few Parameters" on the Set Recordset line. I'm trying to set the parameter in the strSQL line. I want the PartPoolName (in Cobind_qryReport, a query) to equal the TopLvlPoolName on the open form. The SQL for Cobind_qryReport is listed below:</p>
  
  <pre><code>Private Sub btn_Run_Click()
  Dim db As DAO.Database  
  Dim rs As DAO.Recordset  
  Dim strSQL As String  
  Set db = CurrentDb  
  
  strSQL = "Select * FROM Cobind_qryReport WHERE PartPoolName = " &amp; Me.TopLvlPoolName
  
  Set rs = db.OpenRecordset(strSQL)
  
  On Error GoTo Err_PO_Click
  
  If MsgBox("Do you wish to issue the cobind invites?", vbYesNo + vbQuestion, "Confirmation Required") = vbYes Then
  
   rs.MoveFirst
  
    Do While Recordset.EOF = False
  
      DoCmd.OutputTo acOutputReport, "Cobind_rptMain", acFormatPDF, "K:\OB MS Admin\Postage\CoBind Opportunities\Sent Invites\" &amp; [CatCode] &amp; "_" &amp; [PartPoolName] &amp; "Cobind Invite_" &amp; Format(Now(), "mmddyy") &amp; ".pdf"
  
      DoCmd.SendObject acSendReport, "Cobind_rptMain", acFormatPDF, , , , [CatCode] &amp; "_" &amp; [PartPoolName] &amp; " Cobind Invite", "Please find the cobind invite attached. Response is needed by " &amp; [RSVP] &amp; ". Thank you.", True
  
      Recordset.MoveNext
  
    Loop
  
  End If
  
  
  Exit_PO_Click:
      MsgBox ("It didn't work")
      Exit Sub
  
  Err_PO_Click:
      MsgBox Err.Description
      Resume Exit_PO_Click
  End Sub
  </code></pre>
  
  <p>Cobind_qryReport SQL:<br>
  SELECT tblEvents.EventTitle, Cobind_tblPartic.CatCode, Cobind_tblPartic.CodeQty, Cobind_tblPartic.PartPoolName, Cobind_tblTopLvl.RSVP, Cobind_tblPartic.ID
  FROM Cobind_tblTopLvl, Cobind_tblPartic INNER JOIN tblEvents ON Cobind_tblPartic.CatCode = tblEvents.EventCode
  GROUP BY tblEvents.EventTitle, Cobind_tblPartic.CatCode, Cobind_tblPartic.CodeQty, Cobind_tblPartic.PartPoolName, Cobind_tblTopLvl.RSVP, Cobind_tblPartic.ID
  ORDER BY Cobind_tblPartic.ID;</p>
  
  <p>Thank you again for all your help!</p>