B
Bob
In Access 97 code (DAO). I create a new record in a table by using an insert
statement and this is being done inside a transaction. How do I retrieve the
newly created PrimaryKey for further use? The primary key is an autonumber
and is not included in the insert statement.
For instance
Dim sql as string
Dim MyPk as long
Currentdb.begintrans
'some code that executes
sql = "Insert into MyTable (Fielddata1) Values (1)
Currentdb.execute (sql, dbfailonerror)
'at this stage I need to retrieve the newly created Primary and place it
in variable MyPK
'finishing code and closing transaction if successfull
statement and this is being done inside a transaction. How do I retrieve the
newly created PrimaryKey for further use? The primary key is an autonumber
and is not included in the insert statement.
For instance
Dim sql as string
Dim MyPk as long
Currentdb.begintrans
'some code that executes
sql = "Insert into MyTable (Fielddata1) Values (1)
Currentdb.execute (sql, dbfailonerror)
'at this stage I need to retrieve the newly created Primary and place it
in variable MyPK
'finishing code and closing transaction if successfull