Hello.
I'm a fairly advanced .Net programmer and have a few years of experience with Access as well. I'm currently working on a complex Access 2007 DB for a customer and ran into a snag. Hopefully someone has seen this and can offer an easy work-around.
I'll try to keep this as simple as possible:
It seems as though the Sum() function, when applied to a textbox, doesn't work when applied against a query. Here's the SQL of my Query:
The final "IIf" statement ensures that there is some kind of data in there in the event of a Null field (in this case, a zero), but creates a SubTotal of the row.
Here's some sample data that the query shows:
This is all fine and works as expected.
Now, on the sub form that displays this data, I have created a text box in the form footer with the following for the "Datasource":
Here's the kicker - the textbox shows a value of $15.23, which is the first value in the result set, three times (5.08 x 3). If I delete one of the other values, that number becomes the first "subtotal" in the result set multiplied by two. Which leads me to believe that the logic behind the Sum() function is wrong. It appears to be a "for" loop that never moves to the next record, and uses the number of records in the result set as the exit variable.
Any help would be appreciated. Maybe just an MS Office update that needs to be run, perhaps??
Thanks,
Dan
I'm a fairly advanced .Net programmer and have a few years of experience with Access as well. I'm currently working on a complex Access 2007 DB for a customer and ran into a snag. Hopefully someone has seen this and can offer an easy work-around.
I'll try to keep this as simple as possible:
It seems as though the Sum() function, when applied to a textbox, doesn't work when applied against a query. Here's the SQL of my Query:
Code:
SELECT
tblOrders.WRID,
tblOrders.WBS,
tblOrders.StartDate,
tblOrders.Initiator,
(SELECT Sum([qryLaborCost].[PassedCost]) FROM qryLaborCost WHERE qryLaborCost.WR = tblOrders.WRID) AS LaborCostQry,
(SELECT Sum([qryMaterialCost].[ItemPrice]) FROM qryMaterialCost WHERE qryMaterialCost.WR = tblOrders.WRID) AS MaterialCostQry,
(SELECT Sum([qryTravelCost].[Cost]) FROM qryTravelCost WHERE qryTravelCost.WR = tblOrders.WRID) AS TravelCostQry,
IIf(IsNull([TravelCostQry]),0,[TravelCostQry]) AS TravelCost, [LaborCost]+[MaterialCost]+[TravelCost] AS SubTotal
FROM tblOrders;
The final "IIf" statement ensures that there is some kind of data in there in the event of a Null field (in this case, a zero), but creates a SubTotal of the row.
Here's some sample data that the query shows:
Code:
WRID WBS StartDate Initiator LaborCost MaterialCost TravelCost SubTotal
2012000001 12345.ABC 04-Sep-12 Dan 0 5.075 0 $5.08
2012000002 12345.ABC 04-Sep-12 Dan 1275 0 $18.75 $1,293.75
2012000003 12345.ABC 05-Sep-12 Dan 900 0 $35.00 $935.00
This is all fine and works as expected.
Now, on the sub form that displays this data, I have created a text box in the form footer with the following for the "Datasource":
Code:
=Sum([SubTotal])
Here's the kicker - the textbox shows a value of $15.23, which is the first value in the result set, three times (5.08 x 3). If I delete one of the other values, that number becomes the first "subtotal" in the result set multiplied by two. Which leads me to believe that the logic behind the Sum() function is wrong. It appears to be a "for" loop that never moves to the next record, and uses the number of records in the result set as the exit variable.
Any help would be appreciated. Maybe just an MS Office update that needs to be run, perhaps??
Thanks,
Dan