Requery

  • Thread starter Thread starter Jason Frazer
  • Start date Start date
J

Jason Frazer

I'm using Requery. When I run the Requery to current
record changes to first record in the query. How can I
set the current record back to the record that was current
in the form [MSDS] before the Requery was run?
The query name is [MSDS Query].

Thanks Jason
 
Since Requery will always make the first Record (of the re-queried Form
Recordset) the CurrentRecord, you need to navigate back to the previous
(pre-requery) CurrentRecord.

What you need to do (in VBA):

* Hold a Field value that uniquely identify the CurrentRecord on the Form in
a Variable

* Do the requery

* Use saved value to find the required Record in the (post-requery)
Recordset / RecordsetClone of the Form and then set this Record as the
CurrentRecord of the Form (again)
 
Create a variable to cache the value of the primary key(s) then after the
requery, use those values to navigate back to that record using the
FindFirst method on the recordsetclone. For example, using Custid as the
primary key (just a form I had handy):

Dim lngCustid As Long
lngCustid = Me.Custid
Me.Requery
With Me.RecordsetClone
.FindFirst "Custid=" & lngCustid
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
 
Back
Top