Next Record button creates a new record

G

Guest

Hello again folks,

Didn't use to do that before, but now when cycling through records using
Next Record button on my form, when I get to the last record and click on
said button, rather than get a msg pop-up "Can't go to the specified record",
which is what it would previously do, now it just creates a new blank record,
and if I click the button again, it will create another record.

How do I fix this?

The code for this button is as follows:

Private Sub cmdNextRec_Click()
On Error GoTo Err_cmdNextRec_Click


DoCmd.GoToRecord , , acNext

Exit_cmdNextRec_Click:
Exit Sub

Err_cmdNextRec_Click:
MsgBox Err.Description
Resume Exit_cmdNextRec_Click

End Sub

Nothing there to suggest the creation of a new record.

Thanks.
 
K

Ken Snell \(MVP\)

Just like the navigation buttons that are default in ACCESS, using Next
Record will move you to a new record if you're at the last record and your
form's RecordSource is updatable. To prevent this, you'll need to modify
your code slightly:

Private Sub cmdNextRec_Click()
On Error GoTo Err_cmdNextRec_Click

If Me.Recordset.EOF = True Then
MsgBox "cannot go to next record"
Else
DoCmd.GoToRecord , , acNext
End If

Exit_cmdNextRec_Click:
Exit Sub

Err_cmdNextRec_Click:
MsgBox Err.Description
Resume Exit_cmdNextRec_Click

End Sub
 
B

Bill Mosca, MS Access MVP

Richard

So you don't want the user to add new records? If that's the case, change
the form's property "Allow Additions" to No
 

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

Similar Threads


Top