Results 1 to 2 of 2
  1. #1
    peter.nelson is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    1

    Looping through results of a query to run a report

    I have a pretty complex database that uses several queries that all lead to a final query with a parameter (order number). I have a report linked to that query so every time I open the report it asks me for an order number. Once I enter the order number the query is run and I print the report. I am curious if I can create a query that pulls out order numbers (possibly for a date range) and then have a macro or something loop through that query and print a report for each order number. So if the query returned 50 order numbers then the report with the parameter (called Final results) would be printed 50 times. Is there a way to do this?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    Yes, definitely. Open a recordset of the desired order numbers and loop through the recordset using the orderID as filter criteria for the report. I only use VBA, like:

    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.open "SELECT OrderID FROM Orders WHERE <some criteria here>;", CurrentProject.Connection, adOpenStatic, adLockPessimistic
    While Not rs.EOF
    DoCmd.OpenReport "reportname", , , "OrderID=" & rsOrderID
    rs.MoveNext
    Wend
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Looping through a report with subreports.
    By less1die in forum Reports
    Replies: 1
    Last Post: 02-22-2013, 03:15 PM
  2. Report Data Not Matching Query Results
    By Rawb in forum Reports
    Replies: 7
    Last Post: 10-25-2012, 01:41 PM
  3. Looping query
    By jaykappy in forum Queries
    Replies: 13
    Last Post: 02-24-2012, 03:05 PM
  4. Query results into Report
    By VictoriaAlbert in forum Reports
    Replies: 7
    Last Post: 09-01-2011, 10:29 PM
  5. Replies: 3
    Last Post: 05-21-2010, 03:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums