Hi , I have one main form and 2 child forms, there is no link between all these forms, every child form is bounded to a query, lets give the name of child forms, Child1 have the inventory information, and child2 have the ordered information,
now what i'm doing , in child2 i have sum of the products deliverd to customer, in this form i have 3 fields,

Product_Code SumofQuantity CostPrice
A 12 have to know?

now i want to show the cost price , but i need to take this cost price form the child1 form where i have the inventories, in child1 form i have 5 fields,

Inventory_Code Date Product_Code Quantity Price
001 20-aug-02 A 5 20.40
002 22-aug-02 A 36 18.10

now i need to take the product_code and SumofQuantity from Child2 and have to write off from the Child1 form and then need to show the cost price in child2 form, i need to use event procedure in the Cost price field which is in the Child2 form , but how i will know that which product i have sold first, i need to use FIFO method, first i need to sale the first inventory if it finish then got to the 2nd inventory but how shuld i contorl this check?


here is the example for better understandidg,

Inventory(Child1)
code date product quantity cost_per_unit Total value
001 20-aug-02 A 5 20.40 102.00
----------------------------------------------------------
002 22-aug-02 A 36 18.10 651.60
----------------------------------------------------------
Total 41 18.38 753.60
The cost per unit is calculated as Total value/Total quantity , now i sale 12 of these units, leaving 29 in stock
the value of the sale is calculated as follows Using FIFO method (First In First Out)
5 units at 20.40 = 102.00 (these are from the first inventory leaving none left over)

7 units at 18.10 = 126.70 (these are from the new inventory leaving 29 left over,

Total:

12 units combined valued 228.70 (19.06 each)

the 29 units remaining in stock all come from the new inventory and have a valued of 524.90 in total (18.14 each)

please give me any advise how i can solve this task , i realy need to solve it, since last 2 week i'm trying to solve it but no success, may be some one can help me.
Thanks in advance