There is no event that fires when the user leaves a record.
In any case, you don't need to record both the time the user arrives at a
record and also the time they leave it. The time they leave *is* the time
they go to another record, unless they close the form (which I why you want
to log that too.)
So the logging table will have fields like this:
VisitID AutoNumber primary key
DocName Text (64) name of the form
UserName Text who visited the record.
VisitDateTime Date/Time when they visited the record
KeyValue Text primary key value of the record
visited
IsClosed YesNo False unless fired from Form_Close
KeyValue will be Null when they move to the new record, and Null when they
close the form. It will contain a number (if the primary key is a numeric
field), or text (if the primary key is a Text field), or a delimited string
(if the primary key consists of multiple fields.)
As explained, you can then use a subquery to get the VisitDateTime of the
next record for the same UserName + DocName. Filter the main query where
IsClosed = False.