Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting unique ID after INSERT 1

Status
Not open for further replies.

Jarod81

Programmer
Jun 18, 2007
1
CA
In Access, is there a way to get the primary key of a record that I just used an SQL INSERT INTO statement on?

What I'm trying to do is create a record in a parent table, then create several records in a child table (one-to-many). Right now, I'm using two seperate INSERT statements, but to do the second I need the primary key from the parent record. Or is there an easier way to do this?
 
How about:

Code:
strSQL = "Insert Into T (Notes) Values ('abc')"
CurrentDb.Execute strSQL
strSQL = "Select @@identity From T"
Set rs = CurrentDb.OpenRecordset(strSQL)
Debug.Print rs.Fields(0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top