Moving to start of recordset once end is reached (1 Viewer)

DrQuality

New member
Local time
Today, 21:10
Joined
Jul 16, 2002
Messages
6
Hello! I have a recordset (called "hraftr"), and when I reach the end of the recordset, I'd like it to go back to the first entry again. I'm using the following code to do this, but I don't think it's working (or at least it returns a 'no current record' error during the transition):

Dim db as Database
Dim hraftr as Recordset
Set hraftr = db.OpenRecordset "tblCalculations"
For i = 1 to 50
If hraftr.EOF = True Then
hraftr.MoveFirst
Else
hraftr.MoveNext
End If
Next i

I cut a lot out of the code for shortness' sake, but I left everything pertaining to my problem!
Thank you for any help!!
 

RichMorrison

Registered User.
Local time
Today, 15:10
Joined
Apr 24, 2002
Messages
588
Not sure, but I think this is the problem.

When you reach EOF, Access has lost its pointer in the recordset. Therefore it can't MoveFirst.

I think you will have to close the recordset and open it again.

OR

You might be able to store RecordCount and loop until you reach the limit but before EOF. Then you can MoveFirst.

OR

Before each MoveNext, you can create a RecordsetClone and MoveNext in the clone. If you hit EOF in the clone, then MoveFirst in the primary recordset.

HTH,
RichM
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 06:10
Joined
Oct 28, 2001
Messages
2,499
I've put this code on a button to decide whether it should be enabed or not

Private Sub Nextbutton_Click()

Forms![AssetNoFrm].RecordsetClone.MoveLast

If (Forms![AssetNoFrm].CurrentRecord) = (Forms![AssetNoFrm].RecordsetClone.RecordCount) Then
Previousbutton.SetFocus
NextButton.Enabled = False

I'm sure you could replace the nextbutton.enabled=false with
docmd.gotorecord , , acfirst

HTH

Dave
 

Users who are viewing this thread

Top Bottom