Results 1 to 8 of 8
  1. #1
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149

    Running Total in Union Query

    Hi again Guys



    I'm creating a union qury from 3 iffernt queries to calculate the runing balance of a speciic customer. I cant seem to get the running baance to work and my Sql is poor to say the least.

    Any advice on how to do this or what to add in my SQl statement?Click image for larger version. 

Name:	union.PNG 
Views:	33 
Size:	17.2 KB 
ID:	35247Click image for larger version. 

Name:	qury.PNG 
Views:	33 
Size:	17.1 KB 
ID:	35248

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    easy to do in a report.
    add Running total field.

  3. #3
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    Its not a report tho, i'm usin it is a subform displaying the query

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    How about creating another query which just aggregates (totals) the Union Query you just built, and add that total query as another subform under the first one?

  5. #5
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    Click image for larger version. 

Name:	a1.PNG 
Views:	27 
Size:	19.7 KB 
ID:	35251Click image for larger version. 

Name:	a2.PNG 
Views:	27 
Size:	15.2 KB 
ID:	35252

    I trid creatng the second query for the dsumn and get this when I run it. The econd ic is the code Im sing in the qery builder.......

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Whoops, I am sorry. I misread your question. My solution is for a totals row at the bottom of the screen, not for a running total.

    Maybe look at some of the options presented here, and see if you can adapt to work for you:
    https://support.microsoft.com/en-us/...crosoft-access
    https://theaccessbuddy.wordpress.com...m-part-1-of-2/
    https://www.techrepublic.com/article...-access-query/

    Hope that helps!

  7. #7
    JSR is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2018
    Location
    Reno, NV
    Posts
    41
    The only thing I can think of is to append your data to an empty table with the same fields plus an autonumber. Then create a query which has as its input the table you just populated, twice, with no join. Give them an alias of table1 and table2. Group by every field from table1 (except autonumber) and add to the query Sum([table2].[Amount]) Where table2.AutoNumField<=table1.AutoNumField.

    It's messy but I can't think of a better way to do this without using a report.

  8. #8
    Join Date
    Apr 2017
    Posts
    1,792
    Create a saved query like your QustomersTransactionQ, but with an additional field for customer ID, and without WHERE clauses (e.g. QustomerTransactionsUQ).
    Code:
    SELECT "Invoice" AS [Entry], inv.InvoiceID AS [Document], inv.InvoiceDate AS [Transaction Date], cust.CustomerID, inv.InvoiceTotal AS [Amount] FROM CustomersT cust INNER JOIN InvoiceT inv ON cust.CustomerID = inv.Customer
    UNION ALL
    SELECT pay.PaymentMethod AS [Entry], pay.InvoiceID AS [Document], pay.PaymentDate AS [Transaction Date],  cust.CustomerID, -1*pay.Amount AS [Amount] FROM CustomersT cust INNER JOIN PaymentsT pay ON cust.CustomerID = pay.Customer
    UNION ALL
    SELECT "Credit Note" AS [Entry], cred.CreditNoteID AS [Document], inv.CreditDate AS [Transaction Date], cust.CustomerID, -1*cred.TotalCredit AS [Amount] FROM CustomersT cust INNER JOIN CreditNoteT cred ON cust.CustomerID = cred.Customer
    Now you can create a query like (really you can have many different queries with different grouping rules)
    Code:
    SELECT SUM(Amount) FROM QustomerTransactionsUQ WHERE CustomerID = [Forms]![CustomerDataEntryF]![CustomerID]

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

Similar Threads

  1. Running Total Query
    By Plender in forum Queries
    Replies: 3
    Last Post: 06-28-2017, 08:11 PM
  2. Running Total within a Union Query
    By barkly in forum Queries
    Replies: 7
    Last Post: 06-25-2017, 08:30 PM
  3. Help With Running Total Query
    By Njliven in forum Queries
    Replies: 27
    Last Post: 08-06-2014, 10:27 AM
  4. Running Total Query??
    By kwooten in forum Queries
    Replies: 8
    Last Post: 06-15-2012, 06:10 AM
  5. Replies: 1
    Last Post: 06-22-2010, 03:15 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