Results 1 to 2 of 2
  1. #1
    Scorpio11 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2010
    Location
    Cape Town, ZAR
    Posts
    36

    SQL Formula to Sum Itself

    I am busy building an access stock system to calculate inventory. Now in the query in question, I have 2 Option to choose from: Purchases and Sales - to Calculate the purchases, it is easy, i use the below formula

    Cost: IIf([Type]="Purchase",[Amount])

    My Problem comes in when i sell something. To calculate the cost of the item sold, i can pretty much use the above formula and then calculate what the cost of the item is.

    The Sale Formula i am using for the sale is:

    -IIf([Type]="sale",(SELECT Sum(Q1.[Amount])


    FROM qryRunSum2 AS Q1
    WHERE Q1.StockCode=[qryRunSum2].[StockCode] And Q1.[TDate]<=[qryRunSum2].[TDate]))

    The problem with this is, the formula only works the first time for the item in question, evey subssequent time for the same item, the cost calculated is off, - depending on what it was sold for, but the cost being calculated is the second time is not correct as i have an excel sheet to compare it to.

    My question is: can i get the SQL formula get sum itself (from the previous record back), ie: the COST formula. That way, subsequent sales will take the correct Cost of Sale into account and therefore calculate future cost of sales correctly.

  2. #2
    Scorpio11 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2010
    Location
    Cape Town, ZAR
    Posts
    36
    I have attached a sample database that will hopefully illistrate my problem.

    in qryRunSum2 - the column QTY shows a value of 0.00 as the end of all the records, the Column called COST, should show exactly the same number because no items left means no cost left - but i cannot get it to be that way.

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

Similar Threads

  1. Formula in Form
    By jlclark4 in forum Forms
    Replies: 1
    Last Post: 02-03-2011, 04:41 AM
  2. Formula for form
    By chanoc24 in forum Forms
    Replies: 3
    Last Post: 08-18-2010, 10:40 PM
  3. Refine my formula, please
    By DianeG in forum Queries
    Replies: 4
    Last Post: 05-19-2010, 09:20 AM
  4. Formula
    By hschrunk in forum Access
    Replies: 3
    Last Post: 05-18-2010, 01:40 PM
  5. Concatenate Formula
    By Shingo in forum Programming
    Replies: 1
    Last Post: 07-25-2009, 09:14 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