Results 1 to 7 of 7
  1. #1
    ManuelLavesa is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    113

    How to Keep the value of a calculated field before it changes again.

    Hello All, My problem is as follows I have a calculated field called BackOrders: Iff(QtyOrdered > QtyInStock, QtyOrdered-QtyInStock,0). the problem I have is that this value changes as soon as the QtyInStock changes due to a Purchase Order. And then I don't know which invoices had the backorder. Or how many items were in backorder. Is there a way of keeping the previous value. That is the value of the initial calculation. So that I can use it as a filter for finding the invoices that need the items. Or is there a better way of doing this. That is keeping track of backOrders. Thank you for your help and ideas.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Use code to save the calculated value. The real trick is figuring out what event to put the code into and when you want to allow this to happen. If you only want to happen when the record is first created, like:

    If Me.NewRecord And QtyOrdered > QtyInStock Then Me.BackOrder = QtyOrdered - QtyInStock

    And possibly in the QtyOrdered AfterUpdate event. Posted code is VBA but there is macro equivalent.
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If the fields are in the same table, the calculated field data type may be an option.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    ManuelLavesa is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    113
    Thank you both for your answers. I tried June 7 suggestion and unfortunately it is not working. this is what I did. I wrote the following code into the AfterUpdate Event of QtyOrdered.
    Code:
    PrivateSub QrtOrdered AfterUpdate()
    Dim QtyInStock As Integer
    QtyInStock = Me!cbofkProductID.Column(3)
    If me.NewRecord And Me!QtyOrdered >QtyInStock Then me.Parent!QtyBOrder= Me!QtyOrdered - QtyInStock
    End Sub
    The QtyOrdered field is in a continuous form with other Fields which are: Product, QtyOrdered, Price, Discount, Subtotal. Product is in a combobox. The problem I have is as follows. under Normal circustances First I enter the Product, then the QtyOrdered, Then It multiplies Quantity X Price to calculate subtotal, and if there is a Discount it calculates it too. Now when I placed the code above in the afterUpdate Event. The following happens. I enter the product, then the quantity and when I press enter the subform goes blank. The QtyBOrdered displays the proper number. The tables don't record the values for subtotal expected it just places a 0. And when I try to exit it says that it can not save the record because somebody else has modified it. When I finally exit the value for the QtyBOrdered is not recorded on the table, it just says 0. If I remove the code then every thing returns to normal. Do you have any ideas of what could be causing this. Thanks for your help

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why do you reference Parent?

    Where is the QtyInStock value coming from?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  6. #6
    ManuelLavesa is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    113
    FinalDatabaseOrderSales3.zipI reference the Parent because I placed the field QtyBOrder in the Main form and not in the subform. I am enclosing the database so that you can see it. I left the code for QtyOrdered AfterUpdate Event. To find the form go to the button that says "New Sale Order" this will open a form with a subform. The QtyInStock comes from a query called "qryStokInhand" The values come from a union query called "qryStockMovements". All these queries seem to be working ok. To see the problem enter a company, then go to the subform and enter a Product. Check the quantity available which is displayed in the Product combobox column 2. Enter a QtyOrdered which is more than the stockInHand. And you will see that the subform goes blank. the QtyBOrder Field displays the right amount of backorder. But the whole thing becomes unusable... And it does not record the result into the table OrderDetails... Thank for your help I hope you can find what I am doing wrong.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why do you have Order and OrderDetails and Product tables in both the main and subforms? Conventional arrangement would be main form bound to Orders and subform bound to OrderDetails.

    I suggest you simplify the RecordSource for each form before continuing.
    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: 12-30-2014, 01:32 PM
  2. Replies: 4
    Last Post: 03-20-2014, 03:52 PM
  3. Replies: 2
    Last Post: 12-15-2013, 02:29 AM
  4. Replies: 1
    Last Post: 04-21-2013, 03:20 PM
  5. Replies: 3
    Last Post: 02-13-2013, 10: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