Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep from going to first record when requerying?

Making a form in Access 2010. I'm trying to make a button that moves to the next record (or the first if it's at the end), but because I want to account for other users' updates to the data set that have occurred in the meantime, I'm requerying the form before going to the next record.

I'm using the following code, adapted from this SO post:

Private Sub NextRec_Click()

Dim currentID As Long

currentID = Me.id.Value


'Here is where the requery brings the form back to the first record
Me.Requery


With Me.RecordsetClone
    .FindFirst "id=" & currentID
    If Not .NoMatch Then
       If Me.Dirty Then
          Me.Dirty = False
       End If
       Me.Bookmark = .Bookmark
    End If
End With

If Me.CurrentRecord < Me.Recordset.RecordCount Then
    DoCmd.GoToRecord , , acNext
Else
    DoCmd.GoToRecord , , acFirst
End If


End Sub

It's working fine, except that .requery causes the form to briefly return to the first record before going back to the current record and then on to the next record. I don't want it to do this--is there any way I can just keep the current record showing in the form while .requery takes place, instead of showing the first record for the split second while .FindFirst is looking for the record at CurrentID?

like image 493
sigil Avatar asked Jan 27 '26 12:01

sigil


1 Answers

Requery the recordset, not the form itself:

Me.Requery  '<-- resets the current record to the first one in the recordset
Me.Recordset.Requery  '<-- doesn't affect the current record
like image 135
mwolfe02 Avatar answered Jan 29 '26 03:01

mwolfe02



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!