Clicking next when on last record add a new record

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!
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top