Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigation in Subform produces New records

Status
Not open for further replies.

calcul0n

IS-IT--Management
Feb 21, 2002
2
0
0
CA
Hi,

I am working with a databse that uses command buttons in a subform to navigate among records. When I click the "next button" it will navigate to the next record until there are no more, which it then creates a new record. After clicking it again, it will say "cannot access specified record" *duh*.

Here is my code for the button just in case:

Private Sub cmdNextAd_Click()
On Error GoTo Err_cmdNextAd_Click

DoCmd.GoToRecord , "", acNext

Exit_cmdNextAd_Click:
Exit Sub

Err_cmdNextAd_Click:
MsgBox Err.Description
Resume Exit_cmdNextAd_Click

End Sub


Ok, how do I fix this? :)

 
Replace the section of code that moves to the next record with this:

If Not Me.NewRecord Then
DoCmd.GoToRecord , , acNext
End If


Hope this helps!

 
It still creates a new record :[

Any other suggestions??
 
I misunderstood your question. I thought you wanted to move to a new record, but prevent the error when you click the next button on a new record. Here's a way to prevent moving to a new record (there may be a better way, but this seems to work):

DoCmd.GoToRecord , , acNext
If Me.NewRecord Then
DoCmd.GoToRecord , , acPrevious
End If


Another Possibility:
If you don't ever want a new record on the form (not even by clicking a new record button) you might investigate setting the form's Allow Additions (in the Data section of the form's properties) to No. You will have to do some minor coding to prevent the message you get when you click "next record" when you're on the last record. I would be happy to help you with this if you choose to use this solution.

Let me know if this solves your problem.

Lionel
 
Set the "Allow Additions" property in the subform to "No."

mac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top