Results 1 to 2 of 2
  1. #1
    juggernauts is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2014
    Posts
    3

    Need help to Simplify a Complex Calculation on a Form

    Hi,



    As a newbie on Access 2007, I would like to get your expert advice on simplifying calculation on form. I have a form to do search on my item [ItemCode] and display result with its sales records and stock quantity. For my stock calculation, I used following formula:
    Stock quantity at Store = Item Purchase to Store + Item transfer to Store (from Warehouse) – Item Sold from Store – Item transfer from Store (to Warehouse)


    The code I use on my form is
    =Nz(DSum("[Qty]","tblPurchaseOrderDetails","[SentTo] = 'Store' AND [ItemCode] = " & [Forms]![frmStockSearch]![ID]),0)
    +Nz(DSum("[Qty]","tblStockTransaction","[InvAction] = 'Xfer2Store' AND [Location] = 'Store' AND [ItemCode] = " & [Forms]![frmStockSearch]![ID]),0)
    -Nz(DSum("[Qty]","tblStockTransaction","[InvAction] = 'Xfer2Warehouse' AND [Location] = 'Warehouse' AND [ItemCode] = " & [Forms]![frmStockSearch]![ID]),0)
    -Nz(DSum("[Qty]","tblOrderDetails","[SentFrom] = 'Store' AND [ItemCode] = " & [Forms]![frmStockSearch]![ID]),0)


    Where:
    [frmStockSearch] : the form where I did my search.
    tblPurchaseOrderDetails : table for Purchase records which has [SentTo] option for sending item to Store or Warehouse.
    tblStockTransaction : table for item movement form / to Store / Warehouse which has [InvAction] as inventory action (transfer to Store or transfer to Warehouse) and [Location] as Destination of Item (Store or Warehouse).
    tblOrderDetails : table for sales records which has [SentFrom] option for sending item out from Store or Warehouse.
    [ItemCode] : Item Code where I enter on my search form.
    [ID] : the ID of the item.


    This calculation works fine, however you can see the repeating of “ & [Forms]![frmStockSearch]![ID]),0 ” on every parameter. If I have extra warehouse, then this code will be come even longer. Is there any way to simplify this calculation?

    Thank you for your help. I greatly appreciate that.

    Also posted at http://www.pcreview.co.uk/forums/nee...-t4063582.html
    Last edited by June7; 04-01-2014 at 04:31 AM.

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    If this code is in the module for the form [frmStockSearch] itself, then you can replace [Forms]![frmStockSearch]![ID] with Me![ID]. Beyond that however, I dont see anything else you can do. Sometimes complex code is just something we just have to live with.

    HTH

    John

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

Similar Threads

  1. Replies: 4
    Last Post: 02-11-2014, 05:37 PM
  2. Help To Simplify My Code
    By graviz in forum Programming
    Replies: 2
    Last Post: 09-11-2013, 07:58 PM
  3. Complex Expressions on Form Too Slow - Any Better Way?
    By accessbeginner12 in forum Forms
    Replies: 4
    Last Post: 03-29-2013, 03:47 PM
  4. Complex Due Date Calculation
    By JoeM in forum Programming
    Replies: 6
    Last Post: 10-11-2012, 02:12 PM
  5. Need help to simplify this process
    By shanea.kr in forum Access
    Replies: 1
    Last Post: 07-10-2012, 01:40 PM

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