Results 1 to 4 of 4
  1. #1
    lferguison is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5

    Question How to set Variable Criteria in a Query so I can run separate Reports for each Item.

    I have a Report based on a Query that retrieves data from several different Tables for a particular Item. The tables are linked by the Item Number. Currently, I have set the Criteria for the Item Number in my Query to this: Like "IDI 037115" I would like to be able to set the Criteria to a variable "list" of Item Numbers. My intent is to create a "text" file or something of that nature to be "input" into the Criteria as a variable. Then I would like a separate Report to be generated for each Item Number in the list. Is this even possible?

  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
    52,965
    Yes, can be done with code. Open a recordset of the desired records and loop through the recordset to open and close report. What do you want to do with each report - output to PDF?

    SELECT * FROM table WHERE [Item Number] IN ("IDI 037115", "IDI 037120", "IDI 037290");

    Review http://allenbrowne.com/ser-50.html
    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.

  3. #3
    lferguison is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5
    I don't know what you mean by "loop through the recordset". Yes I want to output to PDF for each report.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    Example:

    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM table WHERE [Item Number] IN ('IDI 037115', 'IDI 037120', 'IDI 037290'")
    While Not rs.EOF
    DoCmd.OpenReport "report name", , , "[Item Number]='" & rs![Item Number]
    DoCmd.OutputTo acOutputReport, "", acFormatPDF, "C:\MyPDFs\" & rs![Item Number] & "_" & Format(Date(), "yyyymmdd"), False
    DoCmd.Close "acReport", "report name", acSaveNo
    rs.MoveNext
    Wend

    An alternative to looping recordset is to just loop through a listbox and do the report output on each selected item. You will probably want to loop through listbox anyway to build the IN filter string for the recordset. Could just do the output to pdf instead of building string. The referenced link shows how to loop through a listbox and act on selected items.
    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. Query Criteria for repeated Item
    By rashock in forum Access
    Replies: 3
    Last Post: 01-28-2014, 07:38 PM
  2. Replies: 9
    Last Post: 06-26-2013, 08:28 AM
  3. Query Criteria Based on Item Selected???
    By P.Malius in forum Queries
    Replies: 5
    Last Post: 04-16-2013, 02:09 AM
  4. Replies: 10
    Last Post: 01-06-2012, 07:46 AM
  5. Variable Criteria in Query
    By redpanda in forum Queries
    Replies: 10
    Last Post: 08-03-2011, 08:25 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