View Full Version : Next/previous cycles records


Angello Pimental
06-06-2001, 11:18 AM
I have a form where I navigate from record to record using next/previous buttons.
My question is, when I get to the last record, how can I get the records to cycle back to the first?? And vice versa when I am on the first record and I press previous I want to move to the last record.
Does anybody know the code for this???

D-Fresh
06-07-2001, 04:30 AM
Angello,

Your best bet is to use error handling in your code and if you hit that error, it will move the the first or last record... Here is the code...

'For the Next Button...
Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click


DoCmd.GoToRecord , , acNext

Exit_cmdNext_Click:
Exit Sub

Err_cmdNext_Click:
If Err.Number = 2105 Then
DoCmd.GoToRecord , , acFirst
Else
MsgBox Err.Description
Resume Exit_cmdNext_Click
End If

End Sub

'And now for the Previous record button...
Private Sub cmdPrev_Click()
On Error GoTo Err_cmdPrev_Click


DoCmd.GoToRecord , , acPrevious

Exit_cmdPrev_Click:
Exit Sub

Err_cmdPrev_Click:
If Err.Number = 2105 Then
DoCmd.GoToRecord , , acLast
Else
MsgBox Err.Description
Resume Exit_cmdPrev_Click
End If

End Sub

Hope this helps...

Doug

Angello Pimental
06-08-2001, 06:54 AM
Brilliant!!!

Thanks Doug