When you try to insert a new record in a table that has an
Autonumber field, you may receive the following error message:
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key, or relationship.
Change the data in the field or fields that contain duplicate data, remove the
index, or redefine the index to permit duplicate entries and try
again.
Note The table may not have any relationships or any
indexes.
This problem occurs in Microsoft Office Access
2007 or in Microsoft Office Access
2003.
This problem may occur when the following conditions are
true:
The Access database was compacted.
The table contains an Autonumber field that is not
correctly reseeded.
You install Microsoft Jet 4.0 Database Engine Service Pack
8 (SP8).
You append data from linked table 1 to linked table 2 by
using the Current Database option instead of the
Another Database option. Then you delete the record from
linked table 1 and reappend the same record from linked table 2 by using the
Current Database option.
Re-create the Append queries in the dbFrontEnd.accdb database. To do this, click Append in the Query Type group on the Design tab, and then click Another Database.
Re-create the Append queries in the dbFrontEnd.mdb database.
To do this, click Append Query on the Query
menu in query design view, and then click Another
database.
Open the database that has the table (back-end database) in Access 2007
On the Create tab, click Query Design in the Other group.
In the Show Table dialog box, click Close.
On the Design tab, click SQL view in the Results group.
Type the following in the Query1 window:
ALTER TABLE TableName
ALTER COLUMN AutoNumFieldName
COUNTER(iMaxID,1);
NoteTableName is a placeholder for the name
of the table.AutoNumFieldName is a placeholder for the name of the Autonumber field. iMaxID is a placeholder for the current maximum value in the field plus 1.
On the Design tab, click Run in the Results group.
Access 2003
In the Database window, click Queries
under Objects.
Click New, click Design
View, and then click OK.
In the Show Table dialog box, click
Close.
On the Query menu, click SQL
Specific, and then click Data Definition.
In the Data Definition Query window, type the
following:
ALTER TABLE TableName
ALTER COLUMN AutoNumFieldName
COUNTER(iMaxID,1);
Note The placeholder TableName represents the name
of the table. The placeholder AutoNumFieldName represents the
name of the Autonumber field. The placeholder iMaxID represents the current maximum value in the field plus 1.
On the Create tab, click the down arrow under Macro, and then click Module.
Access 2003
In the Database window, click Modules
under Objects, and then click New.
Paste the following code in the Visual Basic Editor.
Sub ResetAuto()
Dim iMaxID As Long
Dim sqlFixID As String
iMaxID = DMax("<AutonumberFieldName>", "<TableName>") + 1
sqlFixID = "ALTER TABLE <TableName> ALTER COLUMN <AutonumberFieldName> COUNTER(" & <iMaxID> & ",1)"
DoCmd.RunSQL sqlFixID
End Sub
Note The placeholder <AutonumberFieldName> represents
the name of the Autonumber field. The placeholder <TableName> represents the name of the table.
On the Run menu, click Run
Sub/UserForm.
Note You must close the table before you use either method. You do not
have to save the query or the module after you successfully use either
method.
For more information about Microsoft Jet 4.0 Database Engine Service Pack 8, click the following article number to view the article in the Microsoft Knowledge Base:
829558
(http://support.microsoft.com/kb/829558/
)
Information about Jet 4.0 Service
Pack 8