B
BonnieW via AccessMonster.com
I know I'm missing something terribly obvious here, but I just can't put my
finger on it.
I have a table, with many linked tables, and I want to get data from that
table and its linked tables, but only for one record in the "main" table.
The record I'd like to see will *always* be the most recent one, and it has
an autonumber field. I *only* want to see that record; and it'll be feeding
a report. The report will have some user-entered information (once I get a
handle on how to do that), but I'd rather the user not have to enter this ID
number, even though they could if worst comes to worst.
The SQL I have is:
SELECT Max(tblConsEFFORT.ConsEffortID) AS MaxOfConsEffortID, tblConsEFFORT.
Activity, tblNatAreas.NatArea, tblManageUnits.ManageUnit, tblConsEFFORT.
AddlMgmtUnits, tblConsEFFORT.PeopleType, tablePeople.FirstName, tablePeople.
LastName, tblRevegetationNew.RevegType, tblRevegetationNew.PlantID,
tblTrailWorkNew.TrailWorkType, tblInvControlNew.Technique, tblInvControlNew.
TargetPlant, tblInvControlNew.HerbicideType, tblInvControlNew.[%Active],
tblInvControlNew.AmtHerbicide
FROM tblNatAreas INNER JOIN ((((tablePeople RIGHT JOIN (tblManageUnits INNER
JOIN tblConsEFFORT ON tblManageUnits.ManageUnitID = tblConsEFFORT.
ManageUnitID) ON tablePeople.PeopleID = tblConsEFFORT.PeopleID) LEFT JOIN
tblInvControlNew ON tblConsEFFORT.ConsEffortID = tblInvControlNew.
ConsEffortID) LEFT JOIN tblRevegetationNew ON tblConsEFFORT.ConsEffortID =
tblRevegetationNew.ConsEffortID) LEFT JOIN tblTrailWorkNew ON tblConsEFFORT.
ConsEffortID = tblTrailWorkNew.ConsEffortID) ON (tblNatAreas.NatAreaID =
tblManageUnits.NatAreaID) AND (tblNatAreas.NatAreaID = tblConsEFFORT.
NatAreaID)
HAVING (((tblConsEFFORT.PeopleType)<>"crew"));
This is, predictably, telling me that I can't do that, because I didn't
specify aggregate functions for everyone else.
I tried this:
SELECT Max([tblConsEFFORT]![ConsEffortID]) AS Expr1, tblConsEFFORT.Activity,
tblNatAreas.NatArea, tblManageUnits.ManageUnit, tblConsEFFORT.AddlMgmtUnits,
tblConsEFFORT.PeopleType, tablePeople.FirstName, tablePeople.LastName,
tblRevegetationNew.RevegType, tblRevegetationNew.PlantID, tblTrailWorkNew.
TrailWorkType, tblInvControlNew.Technique, tblInvControlNew.TargetPlant,
tblInvControlNew.HerbicideType, tblInvControlNew.[%Active], tblInvControlNew.
AmtHerbicide
FROM (tblNatAreas INNER JOIN ((((tablePeople RIGHT JOIN tblConsEFFORT ON
tablePeople.PeopleID = tblConsEFFORT.PeopleID) LEFT JOIN tblInvControlNew ON
tblConsEFFORT.ConsEffortID = tblInvControlNew.ConsEffortID) LEFT JOIN
tblRevegetationNew ON tblConsEFFORT.ConsEffortID = tblRevegetationNew.
ConsEffortID) LEFT JOIN tblTrailWorkNew ON tblConsEFFORT.ConsEffortID =
tblTrailWorkNew.ConsEffortID) ON tblNatAreas.NatAreaID = tblConsEFFORT.
NatAreaID) INNER JOIN tblManageUnits ON tblNatAreas.NatAreaID =
tblManageUnits.NatAreaID
WHERE (((tblConsEFFORT.PeopleType)<>"crew"))
ORDER BY Max([tblConsEFFORT]![ConsEffortID]) DESC;
Same error.
Is it something in how I have table relationships set up? I'm pretty much a
noob, and this is a handmedown table, so there could be a lot of things going
wrong behind-the-scenes, I suppose.
All of the fields are necessary for the report if they exist, but not all of
them will necessarily have a value- the tblReveg, tblInControl, tblTrailWork
stuff, specificially.
finger on it.
I have a table, with many linked tables, and I want to get data from that
table and its linked tables, but only for one record in the "main" table.
The record I'd like to see will *always* be the most recent one, and it has
an autonumber field. I *only* want to see that record; and it'll be feeding
a report. The report will have some user-entered information (once I get a
handle on how to do that), but I'd rather the user not have to enter this ID
number, even though they could if worst comes to worst.
The SQL I have is:
SELECT Max(tblConsEFFORT.ConsEffortID) AS MaxOfConsEffortID, tblConsEFFORT.
Activity, tblNatAreas.NatArea, tblManageUnits.ManageUnit, tblConsEFFORT.
AddlMgmtUnits, tblConsEFFORT.PeopleType, tablePeople.FirstName, tablePeople.
LastName, tblRevegetationNew.RevegType, tblRevegetationNew.PlantID,
tblTrailWorkNew.TrailWorkType, tblInvControlNew.Technique, tblInvControlNew.
TargetPlant, tblInvControlNew.HerbicideType, tblInvControlNew.[%Active],
tblInvControlNew.AmtHerbicide
FROM tblNatAreas INNER JOIN ((((tablePeople RIGHT JOIN (tblManageUnits INNER
JOIN tblConsEFFORT ON tblManageUnits.ManageUnitID = tblConsEFFORT.
ManageUnitID) ON tablePeople.PeopleID = tblConsEFFORT.PeopleID) LEFT JOIN
tblInvControlNew ON tblConsEFFORT.ConsEffortID = tblInvControlNew.
ConsEffortID) LEFT JOIN tblRevegetationNew ON tblConsEFFORT.ConsEffortID =
tblRevegetationNew.ConsEffortID) LEFT JOIN tblTrailWorkNew ON tblConsEFFORT.
ConsEffortID = tblTrailWorkNew.ConsEffortID) ON (tblNatAreas.NatAreaID =
tblManageUnits.NatAreaID) AND (tblNatAreas.NatAreaID = tblConsEFFORT.
NatAreaID)
HAVING (((tblConsEFFORT.PeopleType)<>"crew"));
This is, predictably, telling me that I can't do that, because I didn't
specify aggregate functions for everyone else.
I tried this:
SELECT Max([tblConsEFFORT]![ConsEffortID]) AS Expr1, tblConsEFFORT.Activity,
tblNatAreas.NatArea, tblManageUnits.ManageUnit, tblConsEFFORT.AddlMgmtUnits,
tblConsEFFORT.PeopleType, tablePeople.FirstName, tablePeople.LastName,
tblRevegetationNew.RevegType, tblRevegetationNew.PlantID, tblTrailWorkNew.
TrailWorkType, tblInvControlNew.Technique, tblInvControlNew.TargetPlant,
tblInvControlNew.HerbicideType, tblInvControlNew.[%Active], tblInvControlNew.
AmtHerbicide
FROM (tblNatAreas INNER JOIN ((((tablePeople RIGHT JOIN tblConsEFFORT ON
tablePeople.PeopleID = tblConsEFFORT.PeopleID) LEFT JOIN tblInvControlNew ON
tblConsEFFORT.ConsEffortID = tblInvControlNew.ConsEffortID) LEFT JOIN
tblRevegetationNew ON tblConsEFFORT.ConsEffortID = tblRevegetationNew.
ConsEffortID) LEFT JOIN tblTrailWorkNew ON tblConsEFFORT.ConsEffortID =
tblTrailWorkNew.ConsEffortID) ON tblNatAreas.NatAreaID = tblConsEFFORT.
NatAreaID) INNER JOIN tblManageUnits ON tblNatAreas.NatAreaID =
tblManageUnits.NatAreaID
WHERE (((tblConsEFFORT.PeopleType)<>"crew"))
ORDER BY Max([tblConsEFFORT]![ConsEffortID]) DESC;
Same error.
Is it something in how I have table relationships set up? I'm pretty much a
noob, and this is a handmedown table, so there could be a lot of things going
wrong behind-the-scenes, I suppose.
All of the fields are necessary for the report if they exist, but not all of
them will necessarily have a value- the tblReveg, tblInControl, tblTrailWork
stuff, specificially.