Hi, I am newbie and I collected a lot of codes from all over the internet but I can't remember where I got this one from which I hope will help you answer your question.
---
Option Compare Database
Option Explicit
'***********************************************************
'This code builds a set of Navigation Buttons consisting of:
'First, Next, Previous, Last, and New
'***********************************************************
Private Sub cmdFirst_Click()
On Error GoTo Err_cmdFirst_Click
DoCmd.GoToRecord , , acFirst
Exit_cmdFirst_Click:
Exit Sub
Err_cmdFirst_Click:
MsgBox Err.Description
Resume Exit_cmdFirst_Click
End Sub
Private Sub cmdLast_Click()
On Error GoTo Err_cmdLast_Click
DoCmd.GoToRecord , , acLast
Exit_cmdLast_Click:
Exit Sub
Err_cmdLast_Click:
MsgBox Err.Description
Resume Exit_cmdLast_Click
End Sub
Private Sub cmdNew_Click()
On Error GoTo Err_cmdNew_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdNew_Click:
Exit Sub
Err_cmdNew_Click:
MsgBox Err.Description
Resume Exit_cmdNew_Click
End Sub
Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click
DoCmd.GoToRecord , , acNext
Exit_cmdNext_Click:
Exit Sub
Err_cmdNext_Click:
MsgBox Err.Description
Resume Exit_cmdNext_Click
End Sub
Private Sub cmdPrevious_Click()
On Error GoTo Err_cmdPrevious_Click
DoCmd.GoToRecord , , acPrevious
Exit_cmdPrevious_Click:
Exit Sub
Err_cmdPrevious_Click:
MsgBox Err.Description
Resume Exit_cmdPrevious_Click
End Sub
Private Sub Form_Current()
On Error GoTo Err_Form_Current
Dim recClone As Recordset
Dim intNewRecord As Integer
' If this is a "New Record" then
' Disable the <Next>, <New>, <Last> buttons
' Enable the <First> and <Next> buttons
' Then Exit the procedure.
intNewRecord = IsNull(Me![RecID])
If intNewRecord Then
cmdFirst.Enabled = True
cmdNext.Enabled = False
cmdPrevious.Enabled = True
cmdLast.Enabled = False
cmdNew.Enabled = False
Me![RecordCount] = "New Record"
Me.txtPlantID_Code.SetFocus ' Set focus to the Plant ID if a "New Record"
Exit Sub
Else
' Else if this is not a new record
' Enable <New> and <Last> buttons
cmdNew.Enabled = True
cmdLast.Enabled = True
End If
' Make a clone of the recordset underlying the form so
' we can move around without affecting the form's recordset
Set recClone = Me.RecordsetClone()
' Check to see if there are no records
' If so disable all buttons except for the <New> button
If recClone.RecordCount = 0 Then
cmdNext.Enabled = False
cmdPrevious.Enabled = False
cmdFirst.Enabled = False
cmdLast.Enabled = False
Else
' Synchronise the current pointer in the two recordsets
recClone.Bookmark = Me.Bookmark
' If there are records, see if recordset is on the first record
' If so, disable the <First> and <Previous> buttons
recClone.MovePrevious
cmdFirst.Enabled = Not (recClone.BOF)
cmdPrevious.Enabled = Not (recClone.BOF)
recClone.MoveNext
' And then check whether recordset is on the last record
' If so, disable the <Last> and <Next> buttons
recClone.MoveNext
cmdLast.Enabled = Not (recClone.EOF)
cmdNext.Enabled = Not (recClone.EOF)
recClone.MovePrevious
End If
Me![RecordCount] = "Record " & (recClone.AbsolutePosition + 1) & " of " & _
DCount("RecID", "tbl_OraclePlantCodes")
recClone.Close
Exit_Form_Current:
Exit Sub
Err_Form_Current:
If Err = 3021 Then
' Error 3021 means recordset is at Add New Record
' Enable <Previous> and <First> buttons
' Disable <Next> and <Last> buttons
cmdPrevious.Enabled = True
cmdFirst.Enabled = True
cmdNext.Enabled = False
cmdLast.Enabled = False
Resume Exit_Form_Current
Else
MsgBox Err.Description
Resume Exit_Form_Current
End If
End Sub