[AccessD] current record of form being reset, can't find the cause

rockysmolin at bchacc.com rockysmolin at bchacc.com
Tue Jan 17 08:51:07 CST 2012


Tom:

I use the same findfirst/bookmark method to set the focus on the record
that had it before a filter was applied, or more often, after a requery.
 

I would just move that code to a function, and call it from whereever in
the code you set the filter instead of using the ApplyFilter event. 
Also, with a function, it will be easy to move the call around in your
code to see where it best works.  You could set the function up to both
save the current record value and return to it by passing it the PK (or
whatever you're using) and a flag to tell the function whether to save
or restore.

HTH

Rocky



-------- Original Message --------
Subject: [AccessD] current record of form being reset, can't find the
cause
From: Tom Zal <tom053 at gmail.com>
Date: Tue, January 17, 2012 6:58 am
To: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>

Hi - I have a puzzle I can't solve. I'm working on a project that
involves
a form (for layout only, no recordsource) with a datasheet subform. When
the user applies or removes a filter or sort on the subform, I want the
current record to remain the same. Access default behavior seems to be
to
lose the current record. I have a function to save the value of a field
of
the current record in the ApplyFilter event, and a function to then look
up
that record using recordsetclone and findfirst in the next Current event
and make it the current record with .bookmark. (If you have a better
method
to suggest that would be great.)

(When the bookmark restores the record, it fires the Current event
again,
but a local variable there has now been set so no recursive loop
happens)

This actually works fine for applying and removing sorts and removing
filters. However when applying a filter, although the current record is
restored, as I can see by single stepping through the code, after the
process finishes, something changes the record to the first record. The
Current event is fired by this change and when I look at the call stack
there, there is nothing but the OnCurrent function of the form. I think
this means that my code did not change the record?

I created a new little database with a table, query, and datasheet form,
and the same function for the same events, and everything works fine
there,
the current record is restored in all cases.

Does anybody have any thoughts about what may be happening? I know
there's
probably not enough info here to identify the problem, but any ideas
would
be appreciated.
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list