move to new record after form requery

  • Thread starter Thread starter msnews
  • Start date Start date
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.
 
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
 
Back
Top