move to new record after form requery

M

msnews

i'm allowing users to add new records on a form.
when the click the add button the form does a requery and goes back to the
first record of the query. how can i move the forms record pointer to the
record that was just added?
the form is bound to a parameterized query.
 
P

PC Datasheet

Assuming you are using an autonumber for the primary key and you have a hidden
textbox on your form for the primary key, put the following code in the OnClick
event of your Add button:

Dim Rst As DAO.Recordset
Dim LastRecordID As Long
DoCmd.Echo False
LastRecordID = Me!NameOfPrimaryKeyTextBox
Set Rst = Me.RecordsetClone
Me.Requery
Rst.FindFirst "[NameOfPrimaryKeyField] = " & LastRecordID
Me.Bookmark = Rst.Bookmark
DoCmd.Echo True
Rst.Close
Set Rst = Nothing


--
PC Datasheet
A Resource for Access, Excel and Word Applications
(e-mail address removed)
www.pcdatasheet.com

· Design and basic development for new applications
· Additions, Modifications and "Fixes" for existing applications
· Mentoring for do-it-yourselfers who want guidance
· Complete application design and development
· Applications Using Palm Pilot To Collect Data And
Synchronize The Data Back To Access Or Excel
 

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