Results 1 to 4 of 4
  1. #1
    sesling is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2011
    Posts
    8

    Help with For Loop in MS Access

    I am using MS Access 2010.
    I have a query that will return 3 values (ZZZ070113,ZZZ070213,ZZZ090713) here is the query (SELECT DISTINCT RUN_ID FROM CUSTOMER where customerID = 1567). These variables will change from time to time. Some times there will be 2 or 4 ID's returned

    I want to take the results and loop through a series of commands to extract records from another table and write the results to a new table.
    So based on some research I have done I figure I need to use a For Each loop statement

    First is how do I assign the values from the query to a variable?
    Then how do I pass these results into a loop so I can see the results?

    Ex. The code would take ZZZ070113 and query table Customer_Details to retrieve ProcessDate and ProcessCount. These value would be written to a new table called CustomerDetails...Then the code would take ZZZ070213 and do the same etc..



    I am not having much success in my searches to find out how to make this work. Any assistance I could get would be greatly appreciated

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why do you need to write to another table? A query that joins tables should be able to return the results.

    Your options:

    1. open a recordset object in VBA and loop through recordset to read each value

    2. open a form based on the query and have VBA procedure cycle through the form records and read each value
    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
    sesling is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2011
    Posts
    8
    The reason I need to write the results to another table is because of our internal audits. I need to be able to show the date/time the query was ran and by who. I was able to create a recordset object in VBA and loop through each ID. The similar threads that got attached to this thread provided some good pointers as well. Thx for your response.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Still don't see why that requires duplicating those records to another table. Could instead have a table that simply saves record of the query or report name, date opened, and by whom.
    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. Replies: 3
    Last Post: 03-10-2013, 07:04 AM
  2. Help with a For Loop in VB
    By JFo in forum Programming
    Replies: 5
    Last Post: 09-29-2011, 02:45 AM
  3. Do While loop
    By jgelpi16 in forum Programming
    Replies: 7
    Last Post: 07-23-2010, 08:21 AM
  4. VBA Loop
    By DreamOn in forum Programming
    Replies: 4
    Last Post: 06-25-2010, 03:35 AM
  5. Issue with while loop and Access 2007 datasheet
    By jermaine123 in forum Programming
    Replies: 2
    Last Post: 01-17-2010, 10:09 AM

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