Here is a procedure I use that is called by all my forms that have custom nav
buttons. The trick here is consistent naming conventions. It enables and
disables the buttons based on the location of the form's current record in
the recordset;
Sub SetNavButtons(ByRef frmSomeForm As Form)
On Error GoTo SetNavButtons_Error
With frmSomeForm
If .CurrentRecord = 1 Then
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
.cmdNextRec.SetFocus
.cmdFirstRec.Enabled = False
.cmdPreviousRec.Enabled = False
ElseIf .CurrentRecord = .Recordset.RecordCount Then
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdPreviousRec.SetFocus
.cmdNextRec.Enabled = False
.cmdLastRec.Enabled = False
Else
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
End If
End With
SetNavButtons_Exit:
On Error Resume Next
Exit Sub
SetNavButtons_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure SetNavButtons of Module modFormOperations"
GoTo SetNavButtons_Exit
End Sub