Full Version: How do I return to original record after Requery?
UtterAccess Forums > Microsoft® Access > Access Forms
rsewell
This question is actually a continuing issue that started here:
http://www.utteraccess.com/forums/showflat...rt=all&vc=1
Noah said "It is possible, but, you have to store the id of the record which you were on just before the Requery (not refresh), and then return to that record AFTER the requery."
Does anyone know how to do this?
Thanks
balaji
Use a dlookup() along with the stored id to return to this record. The access help files should help get you started with the correct syntax etc.
Larry Larsen
Hi
Try:
CODE
dim crId as integer
crId = Me.CurrentRecord
Me.Requery
DoCmd.GoToRecord , , acGoTo, crId

thumbup.gif
rsewell
That worked perfectly!
Larry Larsen
Hi
Great..your welcome.
thumbup.gif
rsewell
Thanks!!
radasys
But there is a more elegant version which causes less flickering.
On error goto errhandler
me.painting = false
vHelp = pID
me.requery
me.RecordsetClone.FindFirst "ID = " & vHelp
me.Bookmark = me.RecordsetClone.Bookmark
errhandler:
err.raise..............
me.painting = true
Have a nice day Thomas
rsewell
radasys... I'll try this one too. Thanks.
rsewell
radasts,
don't understand this code. Please elaborate.
Thanks
ScottGem
The code radasts gave you is similar to the code generated by the combobox wizard when you create a Search combo. The Recordset clone is a copy of the recordset the form is bound to. Find First finds the first instance of the value. By using the PK as the value to find it brings up the one record. The Bookmark then set the current record of the form to the record found.
I use this snippet in lots of places where I want to open a form to a specific record.
rsewell
Do you know of more examples of it here?
ScottGem
not sure what you want examples of
rsewell
ScottGem said: "I use this snippet in lots of places where I want to open a form to a specific record."
guess I'm looking for more examples of this "snippet".
Thanks
ScottGem
Again, that code snippet is what's generated by the combobox wizard. Its basically four lines:
im lngKeyfield As Long
lngKeyfield = primary key
me.RecordsetClone.FindFirst "ID = " & lngkeyfield
me.Bookmark = me.RecordsetClone.Bookmark
All you need to do is substitute something for primary key that will assign the value of the primary key for the record you want to display to lngKeyfield.
fiftyfour
More specifically:
im lngMyVariable As Long
'Set a long numerical variable to the value of your primary key for the active record
lngMyVariable = Me.MyPrimaryKeyFieldName
'Requery the form
Me.Requery
'Create a clone of your form...then find the first record in that clone that matches the primary key value
'from above.
Me.RecordsetClone.FindFirst "MyPrimaryKeyFieldName = " & lngMyVariable
'Once you find that record in the clone, then get the clone's bookmark value for that record. Then set the Form's bookmark to the clone's bookmark value...thus moving to the form's records from which you started prior to the requery.
Me.Bookmark = Me.RecordsetClone.Bookmark
rsewell
Thanks for all your help guys! I get it now. I'm a little slow. confused.gif
radasys
i wouldnt have writtenit better (is this english?)
homas confused.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.