Private Sub Form_Current()
' Provide a record counter for using with
' custom navigation buttons (when not using
' Access built in navigation)
Dim rst As DAO.Recordset
Dim lngCount As Long
Dim nCount As Integer, nPosition As Integer
nCount = Me.Recordset.RecordCount
nPosition = Me.CurrentRecord
If nCount = 0 Then
MsgBox "No Records match your Entry.", vbInformation, " Whoops! "
Exit Sub
End If
Set rst = Me.RecordsetClone
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
'Show the result of the record count in the text box (txtRecordNo)
Me.txtNavStat = "Record " & Me.CurrentRecord & " of " & lngCount
'set buttons enabled by default
cmdFirst.Enabled = True
cmdPrev.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
'disable as appropriate
If nCount = 1 Then
cmdFirst.Enabled = False
cmdPrev.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
ElseIf nPosition = 1 Then
cmdFirst.Enabled = False
cmdPrev.Enabled = False
ElseIf nPosition = nCount Then
cmdLast.Enabled = False
cmdNext.Enabled = False
End If
End Sub