Function GetTopTwo()
'Empty out the final table (TopTwoFinal)
CurrentDb.Execute ("Delete * from TopTwoFinal")
'Table6 is the table that has data in it
'Field1 is the one with a's and b's in it (text field type)
'Field2 is the one with integers in it
'Make sure you go to TOOLS+REFERENCES and pick Microsoft DAO (the highest version
'available, probably 3.6)
Dim rs, rsTopTwo, rsFinal As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select Distinct Table6.Field1 from Table6")
Set rsFinal = CurrentDb.OpenRecordset("Select * from TopTwoFinal")
rs.MoveFirst
While Not rs.EOF
Set rsTopTwo = CurrentDb.OpenRecordset("SELECT TOP 2 Table6.* FROM Table6 " & _
"WHERE Table6.Field1 = '" & rs!Field1 & "' " & _
"ORDER BY Table6.Field2 DESC")
rsTopTwo.MoveFirst
'For the two TopTwo records returned, add them to table TopTwoFinal
While Not rsTopTwo.EOF
rsFinal.AddNew
rsFinal!Field1 = rs!Field1
rsFinal!Field2 = rsTopTwo!Field2
rsFinal.Update
rsTopTwo.MoveNext
Wend
Set rsTopTwo = Nothing
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
Set rsTopTwo = Nothing
rsFinal.Close
Set rsFinal = Nothing
End Function