Send to a Friend

manuel_alarcon's avatar

What is the right access 2007 sql syntax for adding the last record of another table?

Asked by manuel_alarcon (299points) February 23rd, 2010

Im adding records programatically to several tables in an Access2007 database. I find access sql confusing, I’m used to plain simple ol’ sql dialect. So, I have the “project” table which leads all; the “samples” table and the “analysis” and “result” tables, all depending on a “relations” table, being this the one that takes the id’s from project and samples so they can be related later.
Now, all works very nicely but here’s my problem: I can create the new records in the project table, but i need to take the newly created “id” from here and create it into the “samples” and “relations” table, and I’m really confused with the sql syntax.

Im thinking:

DoCmd.RunSQL “INSERT INTO samples (id_sample) VALUES(SELECT Last(project.Id) AS LastOfId FROM project );”

would that be correct?

Using Fluther

or

Using Email

Separate multiple emails with commas.
We’ll only use these emails for this message.