Results 1 to 7 of 7
  1. #1
    rcrobman is offline Not Expert Yet!
    Windows 10 Access 2016
    Join Date
    Apr 2011
    Location
    Toronto
    Posts
    73

    Query to sum data across two tables?

    Boy do I feel inadequate with what I thought would be a simple task.


    What I want to do is to sum up some data that is across 2 tables which I thought would be simple.
    Table 1 has the customer data in it name, address etc and the salesperson and an order number
    Table 2 is linked to Table 1 by the order number and has the sales data in it - there could be multiple lines of sales data for each order number .
    The task:
    On a form display the salesman name and the total of all of his sales for all of the order numbers and count the number of orders - simple in your head add them up order by order that he is responsible for.

    So I have tried various attempts to do so - created new queries, tried using DSum,DCount but no matter what I do I can't make it work.
    Using queries seemed the easiest but no matter how I try and structure the query I get the Salemans name and a list of the Orders and their totals. Have tried using Distinct - nope that doesn't work.
    If I wanted to do this in a report it would be easy - just add the necessary grouping levels, hide the detail and use the Grand Totals - BUT I need the info on a form and you can't put a report on a form.

    So after you finish laughing at my inability to figure this out I would appreciate any suggestions you might have to do what I thought was going to be simple!
    Thanks in advance for any help!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    dsum & dcount are not used in queries. The QUERY does the sum.

    in the query pull in the 2 tables and join them,
    bring down the fields needed,
    click the SUMMATION button (totals)
    then under the $ field, set the TOTAL row, combo box to SUM.

  3. #3
    rcrobman is offline Not Expert Yet!
    Windows 10 Access 2016
    Join Date
    Apr 2011
    Location
    Toronto
    Posts
    73
    Thanks for the reply but have tried that and it does not work for what I want. Yes it does total each of the Order items on each order BUT it gives me the Salesmans name and total for each order in the system whereas what I want is for each Salesman to have one record with the total of all the orders besides it. i.e.
    Joe $20,000 - cumulative total of all of Joes orders.
    Sam $30,000
    Fred $40,00 etc
    Instead I get:
    Joe $4,000
    Joe $8,000
    Joe $8,000
    Sam $10,000
    Sam $20,000

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Can you please post the SQL statement of the query you use?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    In your query make sure you remove all the fields except the salesman name and the Sum for the orders.

    The Group By if you include the order number will add a group for each Order number. As will a date field for example.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    rcrobman is offline Not Expert Yet!
    Windows 10 Access 2016
    Join Date
    Apr 2011
    Location
    Toronto
    Posts
    73
    Thanks a lot for the suggestion that seemed to do the trick . Sad that I have been working with Access for so long and did not know that was the reason it wouldn't work properly!
    Kudos for the help!

  7. #7
    rcrobman is offline Not Expert Yet!
    Windows 10 Access 2016
    Join Date
    Apr 2011
    Location
    Toronto
    Posts
    73
    Thanks for the attempted help! Fortunately the answer was provided by another user!
    Appreciate your willingness to help out!

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

Similar Threads

  1. Query to extract data from Two tables
    By Shamli in forum Access
    Replies: 4
    Last Post: 08-17-2018, 12:19 PM
  2. Replies: 6
    Last Post: 04-03-2017, 08:02 AM
  3. Replies: 6
    Last Post: 08-17-2014, 06:14 PM
  4. Replies: 27
    Last Post: 08-14-2012, 09:05 AM
  5. Getting Data from 2+ Tables Into 1 Query
    By Jakz34 in forum Queries
    Replies: 5
    Last Post: 11-18-2010, 02:35 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