Results 1 to 7 of 7
  1. #1
    Datament is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2023
    Posts
    39

    Calculation and NOt to exceed current balance in Access

    I have three textboxes txt_BegingBal, txt_Pruchase and txtEndBal in a form f_Cash. What code can i use to make sure that purchasers online do not exceed the Begining Balance during a Purchase?



    What i currently have is [txt_BeginBal]-[txt_Purchase]. It allows overage. I need to make sure that the current amount in txt_BeginBal is not exceeded during the purchase.

    Many Thanks in advance for your asistance and suggestions.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    If I understand correctly, then it would seem that

    if txt_purchase > txtBeginBal

    would do the trick.

  3. #3
    madpiet is online now Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    The easiest way might be to declare a variable to hold the result of [txt_BeginBal]-[txt_Purchase] and if that's negative, then you reject the insert. (So you'd check/put the code in the BeforeInsert event of the form).

    something like

    dim Difference as Currency

    Difference = me.
    [txt_BeginBal]-me.[txt_Purchase]

    if Difference < 0 then
    Cancel = True
    Msgbox "Overdrawing account"
    end if

  4. #4
    Datament is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2023
    Posts
    39
    Thanks for the quick response.
    I tried that initially, but I need the txtEndBal to be able to calculate the difference between txt_BeginBal and txt_Purchase, and at the same time flag a message if txt_Purchase is over the limit.

  5. #5
    madpiet is online now Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    Flag a message where/when? When you insert the record?

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    would think the 'flag' would be raised if txtEndBal<0

    so perhaps something like

    Code:
    if txtEndBal<0 then
    
        msgbox "Overspent"
        txt_Purchase=0
    
    end if

  7. #7
    Join Date
    Jun 2022
    Posts
    28
    Use a validation rule on the txt_Pruchase field.

    Code:
    <=[txt_BegingBal]

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

Similar Threads

  1. Opening balance worked into running balance.
    By Perfac in forum Programming
    Replies: 11
    Last Post: 01-09-2018, 01:20 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. Current age calculation in a query
    By cris6381 in forum Queries
    Replies: 5
    Last Post: 09-16-2013, 12:33 PM
  4. How to calculate current balance on hand
    By fazly lee in forum Access
    Replies: 11
    Last Post: 09-05-2012, 09:16 PM
  5. Replies: 12
    Last Post: 06-09-2011, 09:15 AM

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