Public Function TenYearSpan(person as integer) as boolean
'place this code in a public module
'change field and table names to match those in your table.
'Assumes your year field is an integer, not text.
'Also, this code uses DAO so you'll need to ensure that the DAO reference is checked from the VBA editor
'menu Tools>References.
Dim db as DAO.database
Dim rs as DAO.recordset
Dim strSQL as String
Dim consecutive_count as integer
Dim prev_year as integer
Dim myflag as boolean
myflag = false
set db = CurrentDb
strSQL = "Select [[COLOR="Red"]YearFieldName[/COLOR]] From [[COLOR="red"]TableName[/COLOR]] Where (([[COLOR="red"]IDFieldName[/COLOR]]=" & person & ") AND ([[COLOR="red"]YearFieldName[/COLOR]] & "" <> "")) Order By [[COLOR="red"]YearFieldName[/COLOR]] ASC"
set rs = db.OpenRecordset(strSQL,dbOpenDynaset)
If Not rs.EOF Then rs.MoveFirst
Do While Not rs.EOF
if rs![COLOR="red"]YearFieldName[/COLOR] -1 = prev_year then
consecutive_count = consecutive_count+1
if consecutive_count >= 10 then myflag = true
else
consecutive_count = 1
end if
prev_year = rs![COLOR="red"]YearFieldName[/COLOR]
rs.MoveNext
Loop
TenYearSpan = myflag
End Function