|
Question : DSUM - to calculate a running total???
|
|
Hello Experts!! I have 3 tables/with fields: tblPurchaseOrders / PurchaseOrderID, QtyPurchased, ServiceCode tblBilling / PurchaseOrderID, ServiceCode, QtyUsed, DateUsed, Balance tblService / ServiceCode
Parent Form: frmPurchaseOrders - Lists the quantity purchased & service Subform: subfrmPurchaseOrders - lists the DateUsed, Service and QtyUsed, balance
I'm trying to DEDUCT the 'QtyUsed' in 'subfrmPurchaseOrders' from the 'QtyPurchased' in the Parent Form 'frmPurchaseOrders' and give a running balance in the 'subfrmPurchaseOrders/balance' field.
However - this running sum (DSUM?????) must match qualifying criteria. The PurchaseOrderID and the ServiceCode must match. Since Billing is handled as the "Service" is used, it is billed only as the service is used. Not in a lump sum for the entire Purchase Order. (hope that makes sense)
So - if the Customer purchased 10 hours of a service. They might use 1 hour each month, and so each month you would enter the DateUsed, the Amount and Service - which would then deduct this from the Total Quantity purchased on the Parent Form.
I've tried Conditional IF statements (which work thanks to you all) but they dont keep a running total. Is DSUM the correct method?
((now if I assign points - is that based on how difficult I think the problem is???? 8-) I dont want to over-value the question, but seriously.. it's way beyond my current lvl of MS Access comprehension)
|
|
Answer : DSUM - to calculate a running total???
|
|
OK
Enough playing. This *must* be it. Unless I'm fundamentally missing something! DIFF should be the balance already by itself. Use this.
SELECT tblPurchaseOrders.PurchaseOrderID, tblBilling.ServiceCode, (tblPurchaseOrders.QtyPurchased) AS Purch, SUM(tblBilling.QtyUsed) AS Used, (FIRST(tblPurchaseOrders.QtyPurchased) - SUM(ABS(tblBilling.QtyUsed))) AS Diff FROM tblBilling INNER JOIN tblPurchaseOrders ON tblPurchaseOrders.PurchaseOrderID = tblBilling.PurchaseOrderID GROUP BY tblPurchaseOrders.PurchaseOrderID, tblPurchaseOrders.QtyPurchased, tblBilling.ServiceCode ORDER BY tblPurchaseOrders.PurchaseOrderID, tblBilling.ServiceCode
|
|
|
|