ShabanaHafiz
Programmer
I am using Microsoft Access 2003.
In an Access Query, I have one table and one query; LogBook, VHCostPerKM (Vehicle Cost Per KM).
Fields in LogBook table are:
ProjectID
OfficeID
VehicleID
DateOfTravel
KMBeforeTravel
KMAfterTravel
Fields in VHCostPerKM query are:
OfficeID
VehicleID
UnitCost
For a given DateOfTravel, I need to calculate for each ProjectID, OfficeID and VehicleID the following:
Sum of KM Traveled
Cost per Project
KM Traveled is calculated as KMAfterTravel – KMBeforeTravel. I need to multiply the result of KM Traveled with UnitCost to get the Cost per Project. The SQL View of query before Cost per Project is as follows:
For Cost per Project, in the Design View, I tried the following:
Field: Cost per Project: [KM Traveled]*[Unit Cost]
Total: Expression
But got the following error:
You tried to execute a query that does not include the specified expression ‘[KM Traveled]*[Unit Cost]’ as part of an aggregate function
In an Access Query, I have one table and one query; LogBook, VHCostPerKM (Vehicle Cost Per KM).
Fields in LogBook table are:
ProjectID
OfficeID
VehicleID
DateOfTravel
KMBeforeTravel
KMAfterTravel
Fields in VHCostPerKM query are:
OfficeID
VehicleID
UnitCost
For a given DateOfTravel, I need to calculate for each ProjectID, OfficeID and VehicleID the following:
Sum of KM Traveled
Cost per Project
KM Traveled is calculated as KMAfterTravel – KMBeforeTravel. I need to multiply the result of KM Traveled with UnitCost to get the Cost per Project. The SQL View of query before Cost per Project is as follows:
Code:
SELECT LogBook.ProjectID, LogBook.OfficeID, LogBook.VehicleID, Sum([KMAfterTravel]-[KMBeforeTravel]) AS [KM Traveled]
FROM VHCostPerKM INNER JOIN LogBook ON VHCostPerKM.VehicleID = LogBook.VehicleID
WHERE (((LogBook.DateOfTravel) Between [Forms]![rpt2Select]![cboFromDate] And [Forms]![rpt2Select]![cboToDate]))
GROUP BY LogBook.ProjectID, LogBook.OfficeID, LogBook.VehicleID;
For Cost per Project, in the Design View, I tried the following:
Field: Cost per Project: [KM Traveled]*[Unit Cost]
Total: Expression
But got the following error:
You tried to execute a query that does not include the specified expression ‘[KM Traveled]*[Unit Cost]’ as part of an aggregate function