Question

Locked

Dang error: The changes you requested were not successful because they...

By maricaibo ·
Get this error in Access telling me changes would duplicate a record or screw with PK, indexes or relationships. So I build a one table, one field database with one form and a command button to insert 50 records into a table. The only field is not a PK but is indexed and no dupes allowed. Here's the code:

Private Sub cmdEnterTickets_Click()

Dim strSQL As String
Dim intX As Long
Dim Book_No As String


If Nz(Me.txtFirstBookNumber, "") = "" Then

MsgBox "Please enter the Starting Book Number", 48, "Enter Number"

Me.txtFirstBookNumber.SetFocus

Exit Sub

End If


If Nz(Me.txtLastBookNumber, "") = "" Then 'no last number entered

'Insert 50 records in table, beginning with the number in Me.txtFirstBookNumber
'AND update the book_no field for all 50 new records with the number in Me.txtFirstBookNumber
'e.g. number in text box is 700001, insert records with tickets numbered
'from 700001 to 700050 and all 50 new records have book_no as 700001
'This code works:

For intX = Me.txtFirstBookNumber To Me.txtFirstBookNumber + 49

strSQL = "INSERT INTO tblTickets (ticket_no) VALUES (" & intX & ")"


CurrentDb.Execute strSQL, dbFailOnError


Next intX

End If
End Sub

Each new record has a unique number, so how can Access throw this error?

End of my rope, folks. Any suggestions

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums