Hi Dyer,
If I understand your question correctly, I have two suggestions, one being to go with Rudy's solution, the other with the subroutine I provided.
We know that your tblDefects table currently contains Team, DefectDate and DefectCount.
Next, can we confirm that you can or cannot have multiple records for a particular team on a given date e.g. more than one record for Team A on 1/1/02 ... or, is the combination of Team and DefectDate a primary key (unique index). I think you said in your last post that duplicates can exist, but, I need your confirmation.
If Team and DefectDate form a unique index, then Rudy's SQL works perfectly i.e.
SELECT Team, DefectDate, DefectCount
FROM tblDefect AS d
WHERE DefectDate In
(SELECT TOP 80 DefectDate
FROM tblDefect
WHERE Team = d.Team
ORDER BY DefectDate DESC);
If duplicates can exist, then you can use an additional unique identifier (I suggest an autonumber field ... let's call it "Id"

to arbitrate. The one catch is this ... it is imperative that the value of "Id" be sequenced in the same order as their associated DefectDate values i.e. sorting tblDefect records in ascending order by Id needs to also result in the records being in chronological order by DefectDate. If Id order matches DefectDate order, the following SQL will work nicely:
SELECT Team, DefectDate, DefectCount
FROM tblDefect AS d
WHERE Id In
(SELECT TOP 80 Id
FROM tblDefect
WHERE Team = d.Team
ORDER BY Id DESC);
If, however, more than one record can exist for the same Team on a given day AND you cannot guarantee that the value for Id will sequentially match that of the DefectDate value, you should use the procedure I previously supplied.
The good news is that, irrespective of which way you go, all three solutions are dynamic in that they will accomodate changes in Team members etc.
Finally, if either of the two SQL examples work well for you, you can further enhance them to dynamically filter by DefectDate and "team" DefectCount as follows ... first a modified version of the first SQL:
SELECT d.Team, Sum(d.DefectCount) AS [Team Defects]
FROM tblDefect AS d
WHERE (((d.DefectDate) In (SELECT TOP 80 DefectDate
FROM tblDefect
WHERE Team = d.Team
AND DefectDate > [Defect date later than]
ORDER BY DefectDate DESC)))
GROUP BY d.Team
HAVING (((Sum(d.DefectCount))>[Team defects greater than]));
Next, a modified version of the second SQL:
SELECT d.Team, Sum(d.DefectCount) AS [Team Defects]
FROM tblDefect AS d
WHERE (((d.Id) In (SELECT TOP 80 id
FROM tblDefect
WHERE Team = d.Team
AND DefectDate > [Defect date later than]
ORDER BY id DESC)))
GROUP BY d.Team
HAVING (((Sum(d.DefectCount))>[Team defects greater than]));
And lest we forget, if you need to resort to the procedure I supplied you, in which the results are appended into a target table named tblDefectReport, modify the second "strSQL =" statement to read:
strSQL = "SELECT TOP 80 * FROM tblDefects WHERE Team = '" & strTeam & "' ORDER BY DefectDate DESC"
When you run this function, the most recent 80 records for each team will be appended into tblDefectReport. Now you simply need to run one final SQL to summarize and filter your data e.g.
SELECT tblDefectReport.Team, Sum(tblDefectReport.DefectCount) AS SumOfDefectCount
FROM tblDefectReport
WHERE (((tblDefectReport.DefectDate)>[Defect date greater than]))
GROUP BY tblDefectReport.Team
HAVING (((Sum(tblDefectReport.DefectCount))>[Team defects greater than]));
Hope this does it ... good luck !
00001111s