Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In MS Access with an OleDb connection, the process for obtaining the primary key value when executing an Insert Into command is to use the @@Identity property. This property returns the last inserted autonumber value in the current session. To use it, you need to execute a SELECT statement immediately after the INSERT statement to retrieve the value. For example:

  1. Execute the INSERT statement:
INSERT INTO TableName (Field1, Field2, Field3)
VALUES ('Value1', 'Value2', 'Value3');
  1. Execute the SELECT statement to retrieve the autonumber value:
SELECT @@Identity;
  1. Use the value returned by @@Identity as the primary key value.