last record

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

I want to display the message when user is trying to go
beyond last record. For reverse situation when user is
trying to go below the first record I am using code:

If Me.CurrentRecord = 1 Then
MsgBox "It is the first record"
Else
DoCmd.GoToRecord , , acPrevious
End If


What will be the similar code for the last record ??

Thanks for advice.

Tony
 
Hi Tony,

The most common use of this type of code is to create custom navigation
buttons. If that is what you are trying to do you might want to take a look
at Stephen Leban's sample database for custom navigation buttons:

http://www.lebans.com/recnavbuttons.htm

The way I would detect the first or last record is by using the
recordsetclone of the form and then disable any button that allows the user
to scroll beyond the first or last record.

Private Sub Form_Current()
If Not Me.NewRecord Then
With Me.RecordsetClone
If (.BOF And .EOF) Then
MsgBox "There are no records"
'disable both movenext and moveprevious
Else
.Bookmark = Me.Bookmark
.MoveNext
If .EOF Then
'disable move next
MsgBox "This is the last record"
Else
.Bookmark = Me.Bookmark
.MovePrevious
If .BOF Then
'disable move previous
MsgBox "This is the first record"
End If
End If
End If
End With
End If

End Sub
 
Back
Top