BUG: You may receive an error message when you try to insert a new record in a table that contains an Autonumber field in Access 2003 (884185)
The information in this article applies to:
- Microsoft Office Access 2003
SYMPTOMSWhen 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
2003. CAUSEThis 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.
RESOLUTIONRecreate 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.WORKAROUNDTo work around this problem, you must compact the database
and then reset the Autonumber field seed. To compact the database, follow these
steps:
- Start Access 2003.
- Open the Access database.
- If you see the Security Warning dialog
box, click Open.
- On the Tools menu, click Database
Utilities, and then click Compact and Repair
Database.
- If you see the Security Warning dialog
box, click Open.
To reset the Autonumber field seed, use one of the following
methods. Method 1: Use a Data Definition query- 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 TableName is a placeholder for the name
of 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 Query menu, click
Run.
Method 2: Run Visual Basic for Applications code- 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 <AutonumberFieldName> is a placeholder for
the name of the Autonumber field. <TableName> is a
placeholder for the name of 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. STATUSMicrosoft
has confirmed that this is a problem in the Microsoft products that are listed
in the "Applies to" section.REFERENCES
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
Information about Jet 4.0 Service
Pack 8
Modification Type: | Major | Last Reviewed: | 7/15/2005 |
---|
Keywords: | kberrmsg kbcorrupt kbBug kbtshoot kbprb KB884185 kbAudDeveloper |
---|
|