The Code:
Option Compare Database
Option Explicit
Public Sub ShowFirst()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories C;"
End Sub
Public Sub ShowLast()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories C order by C.CategoryID Desc;"
End Sub
Private Sub Form_Load()
ShowFirst
End Sub
Private Sub cmdNext_Click()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories c where C.CategoryID > " & Me!CategoryID & ";"
If Me.RecordsetClone.RecordCount = 0 Then
Beep
ShowLast
End If
End Sub
Private Sub cmdPrev_Click()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories c where C.CategoryID < " & Me!CategoryID & _
" Order by C.CategoryID Desc;"
If Me.RecordsetClone.RecordCount = 0 Then
Beep
ShowFirst
EndIf
End Sub