Results 1 to 10 of 10
  1. #1
    rehmansworld is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    2

    Unhappy How to make Ledger Balance ( AR, AP ) in Access Query ( DO LOOp WHile LOOP)

    How to make Ledger Balance ( AR, AP ) in Access Query ( DO LOOp WHile LOOP)

    I want some body to please make this balance column in QUERY.



    TransactionID TransactionDate SupplierName Description Debit Credit Balance
    Opening Balance 5000
    1 11-03-2015 ABC Receive material 10000 0 15000
    2 11-03-2015 ABC Paid Cash 0 8000 7000
    3 12-03-2015 ABC Receive Material 4000 0 11000
    I also attache simple accdb file please consider it to work for this thread.
    Attached Files Attached Files
    Last edited by rehmansworld; 03-06-2017 at 10:40 AM. Reason: ATTached File

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    I don't believe this can be done as a query. You'd have to write the base data to a table,then loop thru changing the balance as you go.
    if you put it all in a macro ,then it would have the same effect as a query.
    Macro:
    empty report table
    append data to table
    runCode LoopThruBalance()

  3. #3
    Bulzie is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Could you do in query as new column:

    Ledger Balance: IIF([Description] = "Opening Balance",[Balance],IIF([Description] = "Receive material",[Balance]+ [Debit],IIF([Description] = "Paid Cash",[Balance]-[Credit])))

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    or use a subquery

    SELECT *, (SELECT sum(credit-debit) FROM Sales B WHERE ID<=Sales.ID) AS Balance
    FROM Sales
    ORDER BY ID

  5. #5
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    It can be done in a query.

    I use the sub query method that Ajax posted to do this all in a query.

    The concept is to use a sub query to calculate the balance by summing all the previous records up to the and including the current record. There must be a field that can identify the record in sequential order. This is often the primary key if it is sequential (like an autonumber) or a date/time stamp field. For performance , it is best to use a field hat is indexed.

  6. #6
    rehmansworld is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    2
    Thank Yew for helping me every body , can any body please perform this in Ledger.accdb file that i attached with it , i would be very thankful to all of you.

  7. #7
    Bulzie is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Have not used the sub query method much but do like it, seems efficient. But in this case how is it getting the opening balance on each first Supplier record? Would they need to enter the opening balance as a Debit so the sum would pick it up?

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    opening balance is just a transaction so should be in sales table, not in a supplier table.

    @rehmansworld - With regards modifying your db, I won't because you need to understand how it works. Happy to advise, but not to do.

  9. #9
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by Bulzie View Post
    Have not used the sub query method much but do like it, seems efficient.
    You might what to check out: Subquery basics

  10. #10
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by rehmansworld View Post
    Thank Yew for helping me every body , can any body please perform this in Ledger.accdb file that i attached with it , i would be very thankful to all of you.
    The good online forums, like this one, are here to assist in your learning. If we did it for you it would not help you learn, just the opposite.

    Give it a try. If you have trouble, feel free to ask additional questions.

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

Similar Threads

  1. Replies: 12
    Last Post: 06-05-2015, 04:27 PM
  2. General Ledger Query With Opening Balance and Running Balance
    By muhammadirfanghori in forum Queries
    Replies: 3
    Last Post: 03-12-2015, 07:17 AM
  3. Replies: 13
    Last Post: 08-20-2014, 09:17 AM
  4. Replies: 17
    Last Post: 04-07-2014, 07:48 PM
  5. Replies: 3
    Last Post: 03-10-2013, 07:04 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