The first thing that I noticed in reviewing your data is that it appears you have the same fleet item hired out to multiple places at the same time. That would be a data issue, not a code issue. See fleet number 1958 for an example.
You need to review how the data gets into the database and gets updated about the hire status.
1) If the offhire date has been entered in PlantLocation, then is the fleet item possibly still in that location, or is it presumed to be back at a yard somewhere?
2) It might simplify your life to add a yes/no field to PlantLocation that indicates there is a later record.
3) At any case, there needs to be a certain way that you define to know which of the dup records is the correct one. If not, then you need to define an acceptable way to decide which one to use.
4) This SQL code will get you one valid version of the query you request:
Code:
SELECT
FL.FleetName,
FL.FleetNumber,
FL.[S/N],
FL.NextLiftingTest,
FL.HireStatus,
PL2.Address,
PL2.Area,
PL2.PostCode
FROM
Fleet AS FL
LEFT JOIN
(SELECT
PL.FleetNumber,
PL.Address,
PL.Area,
PL.PostCode
FROM
PlantLocation AS PL
WHERE PL.ID IN
(SELECT First(tP1.ID)
FROM PlantLocation as tP1
GROUP BY
TP1.FleetNumber,
NZ(tP1.OffHireDate, NZ(tP1.OnHireDate, Date()))
HAVING
NZ(tP1.OffHireDate, NZ(tP1.OnHireDate, Date())) =
(SELECT Max(NZ(tP0.OffHireDate, NZ(tP0.OnHireDate, Date())))
FROM PlantLocation AS tP0
Where tP0.FleetNumber = tP1.FleetNumber)
)
) AS PL2
ON FL.FleetNumber = PL2.FleetNumber;
It's not particularly pretty, and it's based on these assumptions:
NZ(tP0.OffHireDate, NZ(tP0.OnHireDate, Date()))
For selecting the appropriate PlantLocation record, If the offhiredate is populated, use that as its date. Otherwise, if the onhiredate is populated, then use that. Otherwise use the current date. You'll note that, since the offhire and onhire dates are always past dates, that will give priority to the records that have no dates filled out. If you want to reverse that priority, then change "Date()" to "0" or #01/01/2000# or something low/old, everywhere it appears.
I also made the assumption that, if the dates are the same between different plantlocation records, then any one of them will do. If instead you want the record with the lowest or highest ID, then you can change "First(tP1.ID)" to "Min(tP1.ID)" or "Max(tP1.ID)", respectively.