Microsoft KB Archive/294923

= You cannot use upsized append queries in an Access project in Access 2002 =

Article ID: 294923

Article Last Modified on 11/14/2007

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q294923



Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access project (.adp).

For a Microsoft Access 2000 version of this article, see 229681.



SYMPTOMS
When you try to run an upsized append query in a Microsoft Access project, you may receive the following error message:

Cannot insert explicit value for identity column in table table name when IDENTITY_INSERT is set to OFF.



CAUSE
When you create a new SQL Server database (including SQL Server 2000 Desktop Engine), the IDENTITY_INSERT options are set to OFF.

If you upsize a Microsoft Access table that contains a field of the AutoNumber data type, the field is created on SQL Server as an IDENTITY column. Unlike the AutoNumber data type, you cannot directly edit IDENTITY columns, nor explicitly insert data into an IDENTITY column while the IDENTITY_INSERT option for that table is set to OFF. To insert or update data in an IDENTITY column, you must set the IDENTITY_INSERT option to ON.



RESOLUTION
You can use the SET IDENTITY_INSERT statement to set the IDENTITY_INSERT option. SET IDENTITY_INSERT always references a table, and you should place it before the UPDATE or INSERT statement that modifies or inserts data into an IDENTITY column. The following example sets IDENTITY_INSERT for the NewEmployees table.   SET IDENTITY_INSERT NewEmployees ON



Steps to Reproduce the Behavior
 Open the sample database Northwind.mdb. In the Database window, click the Employees table, and then click Copy on the Edit menu. On the Edit menu, click Paste. In the Paste Table As dialog box, type NewEmployees in the Table Name box. Click OK. Create a new query in Design view, and then close the Show Table dialog box without adding any tables or queries. On the View menu, click SQL View.</li>  Type the following INSERT INTO statement into the SQL window. This statement will create an append query: <pre class="fixed_text">  INSERT INTO NewEmployees (EmployeeID, LastName, FirstName, Title,         TitleOfCourtesy, BirthDate, HireDate, Address, City, Region,          PostalCode, Country, HomePhone, Extension, Photo, Notes,          ReportsTo) SELECT Employees.EmployeeID, Employees.LastName, Employees.FirstName, Employees.Title, Employees.TitleOfCourtesy, Employees.BirthDate, Employees.HireDate, Employees.Address, Employees.City, Employees.Region, Employees.PostalCode, Employees.Country, Employees.HomePhone, Employees.Extension, Employees.Photo, Employees.Notes, Employees.ReportsTo FROM Employees; </li> Save the query as qryAppend, and then close the query.</li> On the Tools menu, point to Database Utilities, and then click Upsizing Wizard.</li> Complete the steps in the Upsizing Wizard, and accept the default selections, except as noted below:

Create New Database: Yes

Which tables do you want to export to SQL Server: Export all tables

Add timestamp fields to tables: No, never

Create a new Access client/server application: Yes

</li> After the Upsizing Wizard is finished, close the upsizing report.</li> Try to run the qryAppend stored procedure, and note the error message.</li>  To set IDENTITY INSERT to ON, add the following line of SQL to the qryAppend stored procedure directly after the keyword AS: <pre class="fixed_text">  SET IDENTITY_INSERT NewEmployees ON When you are finished, your stored procedure should resemble the following text: <pre class="fixed_text">  ALTER PROCEDURE qryAppend AS  SET IDENTITY_INSERT NewEmployees ON   INSERT INTO NewEmployees (EmployeeID, LastName, FirstName, Title,         TitleOfCourtesy, BirthDate, HireDate, Address, City, Region,          PostalCode, Country, HomePhone, Extension, Photo, Notes,          ReportsTo) SELECT Employees.EmployeeID, Employees.LastName, Employees.FirstName, Employees.Title, Employees.TitleOfCourtesy, Employees.BirthDate, Employees.HireDate, Employees.Address, Employees.City, Employees.Region, Employees.PostalCode, Employees.Country, Employees.HomePhone, Employees.Extension, Employees.Photo, Employees.Notes, Employees.ReportsTo FROM Employees </li> Save the modified stored procedure, and then run it. Note that it succeeds.</li></ol>

<div class="references_section">