Results 1 to 4 of 4
  1. #1
    vickyy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    2

    MS Access Code to Update (add/subtract) value (quantity) on a table/form

    I encountered a problem with my MS Access DB and i would




    appreciate any help on here please.


    I have a 'tblStock' with fields 'ProductID', 'InitialStock', 'Buy', 'Sell'


    and 'UpdatedStock'. I also have a form 'StockUpdate' add values


    and also add new records to 'tblStock' . If I have value [100] for


    IntialStock quantity, Buy [0] and sell [10], UpdatedStock will be [90]


    (that's done and fine!). The problem is, I would like to make the


    UpdatedStock value [90] to be the NEW InitialStock, so that any BUY


    or SELL will keep updating the UpdatedStock and making it the NEW


    InitialStock for the next transactions and so on.....but i have been


    struggling to find code to implement this.....Any help will be


    greatly appreciated.


    Thanks in anticipation!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Ideally, would not save stock balance to table, calculate when needed.

    Review: http://allenbrowne.com/AppInventory.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    vickyy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    2

    Ms Access Code.....

    Quote Originally Posted by June7 View Post
    Ideally, would not save stock balance to table, calculate when needed.

    Review: http://allenbrowne.com/AppInventory.html

    I tried it using this code and it's not working

    Private Sub Update_Click()
    Update tblStock
    Set tblStock.InitialStock = tblStock.InitialStock + tblStock.StockUpdate + Forms!StockUpdate!UpdatedStockField
    WHERE tblStock.ModelID = Forms!StockUpdate!ModelID


    End Sub

    Thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Where did you find code like that? Can't reference a table directly. Must open a recordset or use domain aggregate function (DSum, DAvg, Count, DLookup, etc).

    The point I tried to convey is that should not save the balance, should calculate when needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2015, 08:04 PM
  2. Replies: 6
    Last Post: 02-09-2015, 12:17 PM
  3. Replies: 4
    Last Post: 03-31-2014, 02:20 PM
  4. Replies: 12
    Last Post: 03-17-2012, 04:46 AM
  5. Replies: 2
    Last Post: 12-22-2010, 01:46 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