I can't guess exactly right now, but i can get you started. Look into end/beginning of file properties (EOF and BOF). By using them, you can figure out when you're at the end of a recordset. ie.
If rst.EOF then
'you're at the end.
end if
Then look into methods to navigate through recordsets like