Move to specific record

E

Eric C

Hello,

When I requery a form, I am brought back to the first
record in the recordset. How do I move to the record
that was being edited?

Thanks,

Eric C
 
S

Scott Millhisler

What you need to do is save the record
position before you requery the form.
The following is some sample code that
will give you an idea of how this can be done.

The following example assumes that you are
using a data source that supports bookmarks.
For example, Microsoft Jet databases do
support bookmarks so this will work using Jet.
This code also assumes that it reside in a
method of the form so we don't have to
qualify an object to use the Bookmark property.
Looking up Bookmark in the help system will
give you detailed information on its usage.
That Bookmark property also applies to the
Recordset object and it can be very helpful.

< sample >

DIM strTemp As String

' ... code before

Set strTemp = Bookmark
Requery
Bookmark = strTemp

'...code after

I hope this was helpful, please let me know if you have further questions.

Sincerely,

Scott Millhisler

SJM Computer Consulting
 
M

Marshall Barton

Note that since the boomark may be invalidated by the
Requery, it is not a reliable way to do this. Better to
locate the record based on its PK value.
--
Marsh
MVP [MS Access]
 
M

Marshall Barton

Eric said:
When I requery a form, I am brought back to the first
record in the recordset. How do I move to the record
that was being edited?


Use a little code to (re)locate the record. Assuming the
tables prinmary key field is an autonumbe or long integer:

Dim lngKey As Long
lngKey = Me.PKfield ' save record's PK
Me.Requery
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "PKfield = " & lngKey
If Not .NoMatch Then Me.Bookmark = .Bookmark
End If
End With
 

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

Top