G
Guest
I have a query of costs for cars. The cars are given a number and a
status for current or retired. Each car has a make and model.
For each car there are car costs. The cost types are gas, oil change,
body work. Whenever gas cost is entered, the mileage is entered, the
gallons of gas purchased and the total cost.
The report I am working on gives the users a menu to choose 1 or more
cars (multi-select list box) and any kind of scenario for a date range
(month drop down for 1 month, 2 fields for a range, or one of them for
<= or => ).
This reports each car, grouped with the car costs under it by type.
The only thing I am missing is the average mileage for the time period
that is queried. In order to get this, I need to get the min and max
mileage for the queried date range. I have the following control
source for the report:
SELECT tblCar.PKCarID, tblCarNum.intCarNum, tblCarStatus.txtCarStatus,
tblCarMake.txtCarMake, tblCarModel.txtCarModel,
tblCarCostType.txtCarCostType, tblCarCost.DtCostDate,
tblCarCost.intGallons, tblCarCost.CurCostAmount,
tblCarCost.intMileage, IIf([txtCarCostType]="Gas",[intGallons],Null)
AS MyGallons, tblCarCost.PKCarCostID, tblCarCost.FKCostType,
IIf([tblCarCost]![FKCostType]<>6,Sum([tblCarCost]![CurCostAmount]),0)
AS CostNoBod
FROM (tblCarStatus RIGHT JOIN (tblCarNum RIGHT JOIN (tblCarModel RIGHT
JOIN (tblCarMake RIGHT JOIN tblCar ON tblCarMake.PKCarMakeID =
tblCar.FKCarMake) ON tblCarModel.PKCarModelID = tblCar.FKCarModel) ON
tblCarNum.PKCarNumID = tblCar.FKCarNum) ON tblCarStatus.PKCarStatusID
= tblCar.FKCarStatus) LEFT JOIN (tblCarCostType RIGHT JOIN tblCarCost
ON tblCarCostType.PKCarCostTypeID = tblCarCost.FKCostType) ON
tblCar.PKCarID = tblCarCost.FKCar
GROUP BY tblCar.PKCarID, tblCarNum.intCarNum,
tblCarStatus.txtCarStatus, tblCarMake.txtCarMake,
tblCarModel.txtCarModel, tblCarCostType.txtCarCostType,
tblCarCost.DtCostDate, tblCarCost.intGallons,
tblCarCost.CurCostAmount, tblCarCost.intMileage,
IIf([txtCarCostType]="Gas",[intGallons],Null), tblCarCost.PKCarCostID,
tblCarCost.FKCostType;
I have 2 unbound fields on the report.
MinMile: =IIf([intMileage] Is
Null,"",DMin([intMileage],"QryCarStatsRpt"))
MaxMile: =IIf([intMileage] Is
Null,"",DMax([intMileage],"QryCarStatsRpt"))
I get the min for both. I have put these controls in the cost type
header and in the report footer. No difference.
Can anyone give my some guidance as to how to get the min and max
mileage for any given date range?
Thanks!!
status for current or retired. Each car has a make and model.
For each car there are car costs. The cost types are gas, oil change,
body work. Whenever gas cost is entered, the mileage is entered, the
gallons of gas purchased and the total cost.
The report I am working on gives the users a menu to choose 1 or more
cars (multi-select list box) and any kind of scenario for a date range
(month drop down for 1 month, 2 fields for a range, or one of them for
<= or => ).
This reports each car, grouped with the car costs under it by type.
The only thing I am missing is the average mileage for the time period
that is queried. In order to get this, I need to get the min and max
mileage for the queried date range. I have the following control
source for the report:
SELECT tblCar.PKCarID, tblCarNum.intCarNum, tblCarStatus.txtCarStatus,
tblCarMake.txtCarMake, tblCarModel.txtCarModel,
tblCarCostType.txtCarCostType, tblCarCost.DtCostDate,
tblCarCost.intGallons, tblCarCost.CurCostAmount,
tblCarCost.intMileage, IIf([txtCarCostType]="Gas",[intGallons],Null)
AS MyGallons, tblCarCost.PKCarCostID, tblCarCost.FKCostType,
IIf([tblCarCost]![FKCostType]<>6,Sum([tblCarCost]![CurCostAmount]),0)
AS CostNoBod
FROM (tblCarStatus RIGHT JOIN (tblCarNum RIGHT JOIN (tblCarModel RIGHT
JOIN (tblCarMake RIGHT JOIN tblCar ON tblCarMake.PKCarMakeID =
tblCar.FKCarMake) ON tblCarModel.PKCarModelID = tblCar.FKCarModel) ON
tblCarNum.PKCarNumID = tblCar.FKCarNum) ON tblCarStatus.PKCarStatusID
= tblCar.FKCarStatus) LEFT JOIN (tblCarCostType RIGHT JOIN tblCarCost
ON tblCarCostType.PKCarCostTypeID = tblCarCost.FKCostType) ON
tblCar.PKCarID = tblCarCost.FKCar
GROUP BY tblCar.PKCarID, tblCarNum.intCarNum,
tblCarStatus.txtCarStatus, tblCarMake.txtCarMake,
tblCarModel.txtCarModel, tblCarCostType.txtCarCostType,
tblCarCost.DtCostDate, tblCarCost.intGallons,
tblCarCost.CurCostAmount, tblCarCost.intMileage,
IIf([txtCarCostType]="Gas",[intGallons],Null), tblCarCost.PKCarCostID,
tblCarCost.FKCostType;
I have 2 unbound fields on the report.
MinMile: =IIf([intMileage] Is
Null,"",DMin([intMileage],"QryCarStatsRpt"))
MaxMile: =IIf([intMileage] Is
Null,"",DMax([intMileage],"QryCarStatsRpt"))
I get the min for both. I have put these controls in the cost type
header and in the report footer. No difference.
Can anyone give my some guidance as to how to get the min and max
mileage for any given date range?
Thanks!!