Next/previous cycles records (1 Viewer)

Angello Pimental

Registered User.
Local time
Today, 22:31
Joined
May 9, 2001
Messages
92
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

Registered User.
Local time
Today, 22:31
Joined
Jun 6, 2000
Messages
225
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

Registered User.
Local time
Today, 22:31
Joined
May 9, 2001
Messages
92
Brilliant!!!

Thanks Doug
 

Users who are viewing this thread

Top Bottom