Stay on the same record

  • Thread starter Thread starter Pierre-Yves Ste-Marie
  • Start date Start date
P

Pierre-Yves Ste-Marie

In a form, I have many records, with a scroller.
When I make a modification on one, I have this code
Me.Requery
to see the effect of my modification. But with that command, my pointer is
back to
the top of my list .
Any suggestion to stay on the same record I have modified, after the
modification?

Best regards
 
You could also try the following:

Dim r as Long
r = Me.CurrentRecord
Me.Requery
DoCmd.GoToRecord , , acGoTo, r
 
In
Vladimír Cvajniga said:
You could also try the following:

Dim r as Long
r = Me.CurrentRecord
Me.Requery
DoCmd.GoToRecord , , acGoTo, r

That won't work if some other user has added or deleted records from the
recordsource since it was originally queried.
 
In
Pierre-Yves Ste-Marie said:
In a form, I have many records, with a scroller.
When I make a modification on one, I have this code
Me.Requery
to see the effect of my modification.

Do you really need to do this? Would Refresh and maybe Recalc do as
well?
But with that command, my pointer is back to
the top of my list .
Any suggestion to stay on the same record I have modified, after the
modification?

The safest method, if you must requery, is to save the primary key of
the current record before you requery, then relocate to that key
afterward. Here's a basic outline of the code:

Dim vID As Variant

' Save the current record's primary key.
vID = Me.ID ' where ID is the primary key field

Me.Requery

Me.Recordset.FindFirst "ID=" & vID

If the primary key is a text field, you'll need to enclose it in quotes
for the FindFirst criterion:

Me.Recordset.FindFirst "ID=" & Chr(34) & vID Chr(34)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top