Results 1 to 8 of 8

Thread: Balance Field in MS Access

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    15

    Balance Field in MS Access

    hi Guys,

    am using ms access 2003 for my vb6 appliction that has a table for a bank account where all the deposits to the account are entered. Now i want to derive a balance after each entry. i have done it in vb but the problem is that once you make a mistake on one entry, the final balance will be wrong.

    it there a formula in vb or ms accesss that can derive the balance as entries are made and still be able to update the balance once an entry is edited?

    Please Help!!!!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Balance Field in MS Access

    How would you know which entry to make the adjustments on? You can not adjust the balance if it is the sum of a field in your table. You need to identify the offending entry and correct that one so when its added up agian its correct.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    15

    Re: Balance Field in MS Access

    Hi, thanks for response

    am not quite sure i understand you, My code goes a little something like this:
    open database and get last balance
    add depopsit amount to balance
    addnew to table with new balance

    now if i have made 10 entries then i want to edit entry nummber 1, when i edit, the last balance at the bottom will remain the same, hence my question of whether there is a way that the table would adjust the balance field after makeing a change.

    please help am going crazy with this!!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Balance Field in MS Access

    How do you calculate the bottom balance?
    Quote Originally Posted by raketekc
    it there a formula in vb or ms accesss that can derive the balance as entries are made and still be able to update the balance once an entry is edited?
    There is no built in formula, but calculating, it seems, would be as simple as:

    OldBalance + NewBalance = TotalBalance

    If you edit NewBalance, and re-run the forumla, a new total will be created.

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Balance Field in MS Access

    If you had designed the database with two fields: credit and debit, then you would have been able to create an additional field that is a subquery for the running balance.

    The subquery would be something like...

    select table.*, (Select (Sum(debit) - sum(credit)) FROM table_alias where table_alias.datetime <= table.datetime and table_alias.id <= table.id) as runbalance
    from table

    You have to have a means of identifying which records come before the current record... I used date and time combioned with autoinc id (on second thought you can use just that (without the date) instead). table_alias is the same table but contains records only up to the current record in table.
    Last edited by leinad31; Oct 4th, 2005 at 02:50 AM.

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Balance Field in MS Access

    And using credit and debit instead of one field makes it easier to check for erroneous entries... ask any accountant.
    Last edited by leinad31; Oct 4th, 2005 at 01:36 AM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    15

    Re: Balance Field in MS Access

    Thanks guys for your response but i can't seem to get it. My tabel is like this

    ID DETAIL DEBIT BALANCE
    B/forward $300
    1 JOHN $100 $200
    2 PETER $50 $150
    3 ANDREW $50 $100

    Now if i make a change to entry number 2 (PETER), say i put $100 , then my closing balance remains $100 instead of $0. Now i want when i change entry number 2(PETER) the balance field to automatically adjust itself.

    I hope this illustration will help you to see my situation. If there is a way around this please help me get round it.
    Last edited by raketekc; Oct 12th, 2005 at 10:36 AM.

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Balance Field in MS Access

    No your closing balance would be 50 not zero cause you increased peter's debit by 50 not 100... but any way. for it to update automatically, you won't store the balance in the table with the debits/credit. You create a stored query like in the attached db.

    In the sample stoerd query [Runnign_Balance], [ID] was the field used to determine the ordinal value of each entry. By ordinal, we describe its position/place in a sorted list so we know which comes first when calculating the running balance. The limitation with using an autonumber for the ordinal value is we can't "insert" items in the sort list, as in the case of an entry being posted late due to negligence..it will have to be inserted in the middle and not appended... but due to the nature of autonumbers it wil be appended by the sample stored query [Running_Balance]

    But the problem with using date as the ordinal value criteria is we have to ensure it is unique... up to the milliseconds if possible... I'll let you figure that one out youself.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width