one way you can do this is to call a function in vba. so, just off the top of my head, you could write this:
Code:
SELECT Static.FdrName, WPM.Tested, WPM.Name4ID
FROM Static INNER JOIN WPM ON Static.NameID = WPM.Name4ID
WHERE [Years] = (((GetSecondMaxYear(tableName, fieldName))))
GROUP BY Static.FdrName, WPM.Tested, WPM.Name4ID
HAVING (((Static.FdrName)=[Reports]![MainRep]![FdrName]));
and the function that is called with the above sql would be:
Code:
function GetSecondMaxYear(tableName, fieldName) as date
dim rs as dao.recordset
set rs = currentdb.openrecordset("select distinct [" & _
fieldName & "] FROM " & _
tableName & " ORDER BY [" & _
fieldName & "] DESC")
rs.movelast
rs.movefirst
rs.movenext
GetSecondMaxYear = rs.fields(0)
rs.close
set rs = nothing
end function