Clicking next when on last record add a new record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Have a simple form that includes a subform. In the master form I used the
wizard to create buttons for next, previous, first record, last record, add
record.

If a user clicks on the "Last Record" button then whenever they click the
next button instead of getting a message saying there are no more records to
view, it automatically goes into the add routine. I would like a message to
immedately be displayed when if at EOF the user clicks on the next button and
prevent a new record being added or going into a add routine.
Thanks!
 
The easiest way to do that is to test to see if you are on the last record
before moving to the next record. You may want to include the same code in
the Next button because the same thing can happen there.

If Me.Currentrecord = Me.Recordset.Recordcount Then
Msgbox "You are on the last record"
Else
DoCmd.GoToRecord , , acNext
End If

And for the First and Previous record buttons:

If Me.Currentrecord = 0 Then
Msgbox "You are on the last record"
Else
DoCmd.GoToRecord , , acNext
End If
 
Back
Top