You can generate new KeyIDs for each Year group by adding a new Column in the Report Query. Copy the following VBA Code into a Standard Module and save the Code:
Code:
Public Function QrySeq(ByVal fldvalue, _
ByVal fldName As String, _
ByVal QryName As String, _
ByVal ctrlField As String) As Long
'-------------------------------------------------------------------------------
'Purpose: Create Sequence Numbers in Query in a new Column
'Author : a.p.r. pillai
'Date : Dec. 2009
'URL : www.msaccesstips.com
'All Rights Reserved by www.msaccesstips.com
'-------------------------------------------------------------------------------
'Parameter values
'-------------------------------------------------------------------------------
'1 : Column Value - must be unique Values from the Query
'2 : Column Name - the Field Name from Unique Value Taken
'3 : Query Name - Name of the Query this Function is Called from
'4 : Group Column Name - To check & Reset to 1 for each group
'-------------------------------------------------------------------------------
'Limitations - Function must be called with a Unique Field Value like AutoNumber
' - as First Parameter
' - Need to Save the Query after change before opening
' - in normal View.
'-------------------------------------------------------------------------------
On Error GoTo QrySeq_Err
Dim k As Long
restart:
If i = 0 Or DCount("*", QryName) <> i Then
Dim j As Long, db As Database, rst As Recordset
i = DCount("*", QryName)
ReDim varArray(1 To i, 1 To 4) As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset(QryName, dbOpenDynaset)
j = 1: k = 1
Do While j <= i And Not rst.EOF
varArray(j, 1) = rst.Fields(fldName).Value
varArray(j, 2) = k
varArray(j, 3) = fldName
If j <> 1 And j <> i Then
If rst.Fields(ctrlField).Value <> varArray(j - 1, 4) Then
k = 1
varArray(j, 2) = k
End If
End If
varArray(j, 4) = rst.Fields(ctrlField).Value
rst.MoveNext
j = j + 1: k = k + 1
Loop
rst.Close
End If
If varArray(1, 3) & varArray(1, 1) <> (fldName & DLookup(fldName, QryName)) Then
i = 0
GoTo restart
End If
For k = 1 To i
If varArray(k, 1) = fldvalue Then
QrySeq = varArray(k, 2)
Exit Function
End If
Next
QrySeq_Exit:
Exit Function
QrySeq_Err:
MsgBox Err & " : " & Err.Description, , "QrySeqQ"
Resume QrySeq_Exit
End Function
Create a new Query Column and call the QrySeq() Function with correct parameters to generate sequence numbers for each Year Group.
If you need continuous Sequence Numbers for the full Query Records then refer the following Blog Post: Autonumbering in Query Column. The above Code is a variant of this blog post and is intended to publish the solution in an Article next week.
Read the comment section at the top of the Code to pass the parameters correctly when called from a Query Column.
Good luck.