title: Access Report, print pdf per group
body: <p>I am still fairly new to VBA. I have been racking my brains, looked into every forum trying to find how to do this. This is the closest I have got so far.
  I have a table called Streets which a report is based on, showing number of houses per street. Each record is on a single page on a report called StreetPrintOuts. I have the streets split into different regions, and those regions (MapNum) are all numbered. I want each pdf to show all the street records of each street in it's region. So far I have this:</p>
  
  <pre><code>Public Sub PDFGroup_Click()
  Const Folder = "C:\Users\Records\"
  Const Domain = "Streets"
  'Domain can be table name, query name, or sql statement that provides the values to loop
  Const LoopedField = "MapNum"
  Const ReportName = "StreetPrintOuts"
  
  Dim rs As DAO.Recordset
  Dim LoopedFieldValue As Long
  Dim FileName As String
  Dim FullPath As String
  Dim strWhere As String
  Set rs = CurrentDb.OpenRecordset(Domain)
  
  Do While Not rs.EOF
  LoopedFieldValue = rs.Fields(LoopedField)
  FileName = LoopedFieldValue &amp; ".pdf"
  'The field may be a text field. It then must be surrounded in singlequotes. If so uncomment below
  'LoopedFieldValue = "'" &amp; LoopedFieldValue &amp; "'"
  FullPath = Folder &amp; FileName
  strWhere = LoopedField &amp; " = " &amp; LoopedFieldValue
  Debug.Print FullPath
  Debug.Print strWhere
  DoCmd.OpenReport ReportName, acViewPreview, , strWhere
  DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, FullPath
  DoCmd.Close acReport, ReportName
  rs.MoveNext
  Loop
  
  End Sub
  </code></pre>
  
  <p>Every time it runs, it stops after </p>
  
  <pre><code>DoCmd.OpenReport ReportName, acViewPreview, , strWhere
  </code></pre>
  
  <p>With error code Runtime 2501 error: outputto action was canceled</p>
  
  <p>What am I doing wrong?</p>