title: Using MS Access Macro or VBA loop to print individual reports
body: <p>I'm not at all familiar with VBA scripts, but I've tried a few scripts found here and elsewhere online without a lot of luck.</p>
  
  <p>Currently I have a form where a user can press an "Export Report" command button, which opens a prompt asking for an [AgencyID] (a 5 digit id number).  Once the user enters an [AgencyID] a report "rptAgencyReport" is launched which displays information from query "qryAgencyReport" using the criteria "Like [AgencyID]" to query fields from many tables in a print-friendly view.  From here the user can either print the report or save it as pdf or rtf.</p>
  
  <p>My problem is if we want to export a copy of all our files to .rtf format we have to manually select the "Export Report" button, enter the [AgencyID], then save the outputted file.  For 600-700 individual reports this takes days to complete.</p>
  
  <p>What I would like to do is rather than manually entering the [AgencyID] and running each report, I would like to batch export these reports to .rtf files using the [AgencyID] as the filename.  I have a query "exportAgencyID" which contains a lists of all the [AgencyID]s I need to run, but I have not found a way to pass the [AgencyID] as a variable to the report and query.</p>
  
  <p>I've looked at <a href="https://support.microsoft.com/en-us/kb/209790" rel="nofollow">https://support.microsoft.com/en-us/kb/209790</a> but I don't know how to take each record from query "exportAgencyID" and use it as the input required for the query "qyrAgencyReport".</p>
  
  <p>Query "exportAgencyID"</p>
  
  <pre><code>[AgencyID]
  3
  36
  162
  194
  1190
  1345
  . . .
  </code></pre>
  
  <p>Query "qryAgencyReport"</p>
  
  <pre><code>Field: AgencyID
  Table: AgencyMaster
  Sort: 
  Show: checked
  Criteria: Like [AgencyID]
  </code></pre>
  
  <p>tldr; Report displays results of query in a printable form; query results are based on the user entered [AgencyID].  How can I set the [AgencyID] input automatically from a table or query containing all the [AgencyID]s and export a record named [AgencyID].rtf for each [AgencyID]?</p>
  
  <p>Anyone able to help a non-profit save a few days of repetitive work?</p>