VBA Goto record problem

  • Thread starter Thread starter Newboy
  • Start date Start date
N

Newboy

Hi, I am stuck, plelase help.
I have a Continuous form and a button that does a
function, after the function is complete I need to
refresh the form and return to the record I was at.
This is what I have so far:

DoCmd.Close
a = Forms!Agreements.KeyAgreement
Forms!Agreements.Requery
DoCmd.GoToRecord , , acNext
DoCmd.GoToControl "SENT_DATE"

The first 3 line work fine, I just can't get the
GoToRecord to work.
 
The "trick" to doing this is to store the primary key field's value before
you do the requery, then move to the record with that primary key value:

DoCmd.Close
Dim varKey As Variant
a = Forms!Agreements.KeyAgreement
varKey = Forms!Agreements.PrimaryKeyField.Value
Forms!Agreements.Requery
Forms!Agreements.RecordsetClone.FindFirst "PrimayKeyField=" & varKey
Forms!Agreements.Recordset.Bookmark =
Forms!Agreements.RecordsetClone.Bookmark
DoCmd.GoToRecord , , acNext
DoCmd.GoToControl "SENT_DATE"
 
Thanks Ken, I followed your example and it worked fine, I
guess I was going in the right direction but I didn't
know about setting a RecordsetClone.Bookmark
 
Back
Top