Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    vickimurray is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Oklahoma City, OK
    Posts
    22

    Open multiple queries, change date range, run and close


    Using Access 2010, I have a number of queries used in sub-reports for my master report. At the beginning of the month, I need to open each query, change the date (it will be the same date range for all of the queries) criteria(s), run the query, close it and then move on to the next query and do the same thing. Since I have over a 100 queries to accomplish the massive reporting involved, I really don't want to do this individually. Anyone have any ideas? I've tried to figure out how to do this with a macro but have had not luck in working through it so far. About have the queries use a "between" date range and the other half are grouped by month so they use a "month year" range. Most of the queries have multiple criteria so the date criteria might be used up to 10 times in one query.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    I'd create a form for the user to enter the desired criteria, and have all the queries point there:

    Between Forms!FormName.FromDateTextbox And Forms!FormName.ToDateTextbox
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    vickimurray is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Oklahoma City, OK
    Posts
    22

    Way past me... sounds good but don't know where to begin.

    Quote Originally Posted by pbaldy View Post
    I'd create a form for the user to enter the desired criteria, and have all the queries point there:

    Between Forms!FormName.FromDateTextbox And Forms!FormName.ToDateTextbox
    Sorry that I did not mention that I a TOTALLY new to the Access macros. I've just finished teaching myself how to build the reports and accomplished that but now I want to figure out how to automate the updating each month.
    I was assuming that I would have to set the date range as variables but that is about the extent of my knowledge, especially with this Macro Designer. That said, I think I have the theory of what you are talking about but do not have a clue of where to begin or how you would "point" a query to the form? or where the date criteria would be stored from the form. Am I just trying to bite off too much at this point?

    Oh, and "yeah John Galt"!!!!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    Quote Originally Posted by vickimurray View Post
    how you would "point" a query to the form? or where the date criteria would be stored from the form. Am I just trying to bite off too much at this point?

    Oh, and "yeah John Galt"!!!!
    What I posted would be your new criteria, instead of

    Between #8/1/12# And #8/31/12#

    The dates aren't "stored" anywhere, they're just sitting on the form available for the query to look at.

    John rocks!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    vickimurray is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Oklahoma City, OK
    Posts
    22
    Thanks! I was going to ask where to find some good tutorials and/or reference books. I'll check this out for sure.

  7. #7
    vickimurray is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Oklahoma City, OK
    Posts
    22
    OK, I'll work on that. Any idea on what I would use when the criteria is "July 2012" for the month summary criteria?

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    You could either have the user type that in, or provide month and year combos with a hidden textbox that combines the two selections to result in the desired format.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    vickimurray is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Oklahoma City, OK
    Posts
    22
    I tried this. As far as I can see it is the same as entering a Query Parameter (e.g.: Between [Start Date] And [End Date] ) which I thought before was going to be my answer by using the same Parameter names in all the queries; however, when I tried that, every time I open and update each of the queries, I have to type in the starting and ending dates... trust me, this gets old VERY fast with as many queries as I have to update! Is there a way that I can set a variable to the parameter name that is used across multiple queries so that I only have to type in the start date and the end date one time?

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728
    Can you show us what you tried exactly?

    Perhaps you could show us the SQL for a few of these queries, and identify what parameters are required.
    That way we can see some actual data rather than guessing at what you have.

    Sounds like you could have a form as Paul suggested, and a button to run a number of queries, sequentially, after inserting the appropriate parameters in a BETWEEN.....

  11. #11
    vickimurray is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Oklahoma City, OK
    Posts
    22
    Being new to the forum, could you tell me how to show you the SQL???

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728
    I don't have acc2010, but if you select a query; go to the query design window and select SQL view, it will show the sql of your query.
    You can copy and paste the sql into this forum.

  13. #13
    vickimurray is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Oklahoma City, OK
    Posts
    22
    This is a screenshot of my query currently:

    CompanyName is text; Activity Date is a date field; all others are Yes/No fields

    First I tried

    1. creating a form named “FromDateTextbox” with a textbox (named also “FromDateTextbox”)
    2. creating a form named “ToDateTextbox” with a textbox named “ToDateTextbox”
    3. went to query and set criteria (using Builder) to

    Between [Forms]![FromDateTextbox]![FromDateTextbox] And [Forms]![ToDateTextbox]![ToDateTextbox]

    Results: Popped up an error message:
    “This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the express to variables.”

    Then I tried:

    1. Typed directly into criteria: Between Forms!FormName.FromDateTextbox And Forms!FormName.ToDateTextbox
    2. Which was changed to: Between [forms]![FormName].[FromDateTextbox] And [Forms]![FormName].[ToDateTextbox]


    Result: popped up a dialog box for a parameter value:
    Click image for larger version. 

Name:	FromDateDialog.jpg 
Views:	12 
Size:	9.5 KB 
ID:	8822, entered value, 2nd dialog box: Click image for larger version. 

Name:	ToDateDialog.jpg 
Views:	12 
Size:	8.7 KB 
ID:	8823, entered value.

    This worked but it’s the same as just typing in a criteria “ Between [Start Date] And [End Date]
    When I tried that previously for all the “Between” queries, I had to enter the date every time… I have this criteria for 72 queries so I would like to find some form of assignable variable or find out how I’m creating the form Paul suggested incorrectly (as I am sure it is me, not Paul's solution, that is the problem)
    Does that help?
    Attached Thumbnails Attached Thumbnails current query.jpg  

  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728
    Select 1 query, go to query design view, change to show SQL, copy the SQL,
    paste the sql in a post.

    Don't execute anything.

    here's aa link showing how to get to sql view in 2007.
    http://www.youtube.com/watch?v=_pE7S-lzpa4

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    You realize the form has to be open when the query runs? The query won't open it for you. If it is open and you get the parameter prompt, something is spelled wrong.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 06-10-2012, 02:29 PM
  2. Date Range Report with Multiple Date Fields
    By StevenCV in forum Reports
    Replies: 13
    Last Post: 02-29-2012, 08:29 AM
  3. Multiple Field & date range filter
    By mrkandohi001 in forum Reports
    Replies: 6
    Last Post: 01-18-2012, 03:11 AM
  4. Query with multiple date range constraints.
    By younggunnaz69 in forum Queries
    Replies: 2
    Last Post: 12-26-2011, 10:45 AM
  5. Replies: 3
    Last Post: 09-29-2009, 07:08 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