Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30

    Report using totals from 2 queries...

    I have a database that is used to record training hours. I have queries set up for each year that dump into a report that lists each staff member and then totals the training hours for that year (using the sum feature). I need to get a report that will list the staff name and then 2 years' totals, side by side.



    Ex.

    staff name 2011 2012
    Mr. X 23 45

    I know there is probably a simple solution, but I do not know Access very well and I just cannot figure this out. Thanks in advance for your help.

    Lauren

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    One way.

    First create three queries,
    1. List of all staff members
    2. 2011 totals
    3. 2012 totals

    Now use, outer joins to link the 2011 and 2012 totals queries back to the list of all staff members in a new query. Use this query as the source of your report.

  3. #3
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    Thanks JoeM, I am wondering how you do the totals in the query then? In the report I have, I used the query to define the dates, then in the 2011 report I used =Sum([hours]) to get the totals. I can do that in the query?

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Take a look at doing Aggregate (Totals) Queries in Access' built-in help files. These are very useful queries that you will probably find many uses for!

  5. #5
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    Thanks so much!

  6. #6
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    I've got the 2 queries and they work great. Now, I am confused about outer joins. I will see what I can find on the forum.

  7. #7
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    There is the 2 queries - only 1 table. How do I do an outer join with just one table?

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You want your final query to include all three other objects:
    1. Your staff listing table/query
    2. Your 2011 totals query
    3. Your 2012 totals query

    In the query builder, drag a relationship line from your staff listing to your 2011 totals query to join the two. Then double-click on the join line itself, and a box should pop-up showing three options. You want to choose the ones that says something like "Include all the records from your staff listing and only the matching records from your 2011 totals query". If you do this properly, your join line will have an arrow on the end pointing to the 2011 totals query.

    Now repeat the exact same process from your staff listing to the 2012 totals query.

    Then, just select the fields you want from each object. Note that if you have people who appear in the 2011 totals, but not in the 2012, you will have a NULL value in that 2012 amount field for that person. If you wish to change that NULL to a zero, use the NZ function (see help for details).

  9. #9
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    It keeps telling me that the name can come from more than one source when I run the report. This is the sql.

    SELECT Query1.[Workshop Data].[Staff Member].Value, [Query 2].SumOfHours, Query1.SumOfHours, Query1.[Staff Table].[TSA Staff Name]
    FROM [Query 2], Query1;

  10. #10
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Two problems:
    1. There should be three queries in your SQL code (I only see two).
    2. You have not defined the relationships between your queries (read the instructions I posted in my previous post).

  11. #11
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    oops wrong one. It says that I have ambiguous outer joins if I try to run it.


    SELECT [Staff Table].[TSA Staff Name]
    FROM ([Staff Table] RIGHT JOIN Query1 ON [Staff Table].[TSA Staff Name] = Query1.[Workshop Data].[Staff Member].Value) RIGHT JOIN [Query 2] ON [Staff Table].[TSA Staff Name] = [Query 2].[Workshop Data].[Staff Member].Value;

  12. #12
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    am going to delete the queries and start over.

  13. #13
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Make sure that the fields you are joining are the exact same type (not trying to join Text to Numeric or vice versa). I mention that because I see that you have ".Value" after some of the field names.

  14. #14
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    ok. This is what I have now.

    SELECT Query1.[TSA Staff Name], [Query2 2011].SumOfHours, [Query2 2012].SumOfHours
    FROM (Query1 LEFT JOIN [Query2 2011] ON Query1.[TSA Staff Name] = [Query2 2011].[Workshop Data].[Staff Member].Value) LEFT JOIN [Query2 2012] ON Query1.[TSA Staff Name] = [Query2 2012].[Workshop Data].[Staff Member].Value;

  15. #15
    TSALauren is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    30
    the fields I am joining are the same, it's how they are set up I think because there is a drop down for choosing the staff names and that is how it lists it?? Does that make sense?

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

Similar Threads

  1. Sub Total and Overall Totals in a Report
    By StevenCV in forum Reports
    Replies: 3
    Last Post: 02-27-2012, 08:09 AM
  2. Report with monthly totals?
    By KrisDdb in forum Access
    Replies: 7
    Last Post: 12-06-2011, 11:49 AM
  3. Replies: 5
    Last Post: 12-06-2011, 11:18 AM
  4. Graph totals queries with different data
    By maggioant in forum Queries
    Replies: 0
    Last Post: 10-01-2009, 12:12 PM
  5. Replies: 0
    Last Post: 06-07-2007, 02:33 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