Results 1 to 9 of 9
  1. #1
    wickrama is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    5

    User queries for past week and month sums, averages, etc

    I want to make a query that can calculate averages and counts, etc. for the previous week and the previous month. Ideally, the user could enter in a date range for the query to run. However, I want this to be in user-facing. In other words, I want them to be able to do all this easily without having to modify the query. Is this possible? Thanks.

  2. #2
    JSR is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2018
    Location
    Reno, NV
    Posts
    41
    Use parameters. In the query design, for the field [date_field] on the criteria line, type >=[enter start date], and in another column [date_field]<=[enter end date]. When the user runs the query, Access will ask for "enter start date" and "enter end date" and that query will return rows with date between the two.

  3. #3
    wickrama is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    5
    Thank you, that worked as you said. Now how do I design the query so that instead of returning rows with the date between the two entered, it returns a count of the number of entries between those dates?

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    just change the query to an aggregate (group by) query and count the PK. Click on the Totals option on the ribbon in the query design window

  5. #5
    wickrama is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    5
    I did this, and I get an error message which says the expression is typed incorrectly or is too complex. The only change I made was adding the totals option and changing it to "Count"

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    show the sql that was generated

  7. #7
    wickrama is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    5
    SELECT Count(Nutrition.Date_of_admission) AS CountOfDate_of_admission
    FROM Nutrition
    HAVING (((Count(Nutrition.Date_of_admission))>=[enter start date] And (Count(Nutrition.Date_of_admission))<=[enter end date]));

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    you are trying to compare a count with a date. try

    Code:
    SELECT Count(Nutrition.Date_of_admission) AS CountOfDate_of_admission
     FROM Nutrition
    WHERE Nutrition.Date_of_admission>=[enter start date] And Nutrition.Date_of_admission<=[enter end date]
    Just copy and paste the code into a new query

    Note: please get used to using the code tags when posting code

  9. #9
    wickrama is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    5
    Worked. thank you!!

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

Similar Threads

  1. experiencing 3024 error in the past week?
    By yeah in forum Programming
    Replies: 4
    Last Post: 05-17-2018, 07:57 AM
  2. Replies: 26
    Last Post: 11-05-2015, 01:58 PM
  3. Replies: 3
    Last Post: 11-26-2012, 01:24 PM
  4. Query to show averages by month
    By DDEB in forum Queries
    Replies: 3
    Last Post: 05-08-2012, 05:11 PM
  5. Rolling 3 Month sums
    By michaeljohnh in forum Reports
    Replies: 1
    Last Post: 11-08-2010, 05:51 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