ACC2002: @@IDENTITY Returns Incorrect Identity Column Value (275090)
The information in this article applies to:
This article was previously published under Q275090 Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies only to a Microsoft Access project (.adp).
SYMPTOMS
When you enter new data into a Microsoft Access database, your entry is immediately replaced by incorrect values.
-or-
When you enter new data, you receive the following error message:
The data was added to the database but the data won't be displayed in the form because it doesn't satisfy the criteria in the underlying record source.
CAUSE
This behavior occurs because the @@IDENTITY function is used to resynchronize data after new records are added. This function returns the last identity column value created in the current session. When you add a new record, the Cursor Engine uses the @@IDENTITY function to resynchronize all records and ensure that all data is available.
RESOLUTION
To work around this issue, use one of the following methods.
Manually Refresh the Records
To view the data that you have just entered, click Refresh on the Records menu. By doing so, you update your display with the most current data.
Automatically Refresh the Records
Alternatively, you can use a form to add records and use the form's AfterInsert event to refresh the form. By doing so, the cursor is repositioned on the first record after the record is added. You can use the GoToRecord method to move to a new record.
- In the database window, click the table where the problem is occurring to select it.
- On the Insert menu, click Form.
- Click AutoForm: Datasheet in the New Form dialog box, and then click OK.
- On the View menu, click Design View.
- On the View menu, click Code to display the Visual Basic Editor.
- Type or paste the following code in the Visual Basic Editor:
Private Sub Form_AfterInsert()
' Refresh the form after records are added
Me.Refresh
' OPTIONAL: This code will place the cursor on
' the first record. Use the GoToRecord method
' to move the cursor to a new record.
DoCmd.GoToRecord , , acNewRec
End Sub
- On the Visual Basic Editor File menu, click Close and Return to Microsoft Access.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCES
For more information about the @@IDENTITY function, see SQL Server Books Online at the following MSDN Web site:
Modification Type: | Major | Last Reviewed: | 11/5/2003 |
---|
Keywords: | kbbug kberrmsg kbpending KB275090 |
---|
|