Requery form returns to first record.

G

Grant

How come when I do a requery method it returns to the first record? And how
can I get back to where I was?

Thanks in advance for the replies.
Grant.
 
A

Allen Browne

A requery reloads all the records into the table, so it's like reopening the
form and you find yourself back at the beginning record.

If you want to return to the current record again after the requery, save
the primary key value into a variable, and find the record again in the
RecordsetClone of the form. This example assumes a numeric primary key named
"ID":

Dim varID as Variant 'To save the primary key.
If Me.Dirty Then 'Save any changes.
Me.Dirty = False
End If
varID = Me.ID 'Save the primary key value.
Me.Requery

'Find the record again
With Me.RecordsetClone
If IsNull(varID) Then 'Must have been at new record.
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
Else
.FindFirst "ID = " & varID
If .NoMatch Then
MsgBox "Not found."
Else
Me.Bookmark = .Bookmark
End If
End If
End With
 

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