VBA Goto record problem

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.
 
K

Ken Snell

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"
 
N

Newboy

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
 

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