Results 1 to 4 of 4
  1. #1
    jedwards85 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Posts
    2

    Run Query based on date for Multiple days

    I am currently working on a DB that stores a list of sales reports that get produced by the sales org in a simple table.
    The reports produced regularly are classified as daily, weekly, monthly, or quarterly, and depending on the type, there is some additional information captured (i.e. for weekly reports, what day of the week they are produced).



    I have successfully created a query that takes a date entered on a form by the user, and returns all reports that should be produced that particular day including the daily, weekly, monthly etc. in a report.
    Now I want to be able to run this same query & report for either a range of dates entered by the user, or have the user enter one date, and have the report generate all the sales reports for the next 30 days.

    Can I somehow iterate through my existing query in a loop between a begin and end date or is there a better approach to take?
    The output should be arranged by date to form a forecast view such as:

    Tuesday March 29, 2011
    Daily Report 1
    Daily Report 2
    Daily Report 3
    Weekly Tuesday Report 1
    Weekly Tuesday Report 2
    Monthly Report for the 29th

    Wednesday March 30, 2011
    Daily Report 1
    Daily Report 2
    Daily Report 3
    Weekly Wednesday Report 1
    Monthly Report for the 30th
    Last edited by jedwards85; 03-29-2011 at 11:03 AM. Reason: Format

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not in the query, but it wouldn't be hard to set up a loop in VBA to take two dates input by a user and run the queries for each date between them. It looks like you'll have the additional wrinkle of having to test what day it is and running different reports based on that? Check out Do...Loop in VBA help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jedwards85 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Posts
    2
    Thanks, that's what I was thinking, and yes i think you're right about testing for what the day is.

    I'll see if I can find a similar use of loops but haven't had much luck to this point.

    Would this need to create a temporary table to store the data as it iterates through the days to query or is there a better way?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Unless I've misunderstood what you're doing, no temp table should be required. You'd just place the current date from the loop into the form you already have working, and run/print/save/whatever your reports. The basics of the loop:

    Code:
      Dim dteDate                 As Date
    
      dteDate = Me.StartDate
      Do While dteDate <= Me.EndDate
        Debug.Print dteDate
        dteDate = dteDate + 1
      Loop
    That's just printing the date out to the VBA Immediate window for testing. You'd copy dteDate to your form and run your reports.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 11-12-2010, 01:16 AM
  2. Replies: 2
    Last Post: 04-27-2010, 01:25 PM
  3. Replies: 3
    Last Post: 09-29-2009, 07:08 AM
  4. Replies: 2
    Last Post: 07-31-2009, 06:56 AM
  5. 90 days in the pass - Date help wanted
    By techexpressinc in forum Queries
    Replies: 1
    Last Post: 01-26-2009, 07:13 AM

Tags for this Thread

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