autonumber field and inserting using sql statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I use an sql statement to insert a record into a table, is there a way
to know what autonumber value was assigned so that I can update related
tables with that value in code?
 
Suzy:

Depending on your version of Access, your alternatives could include using
the SELECT @@Identity query, or reading the value from a recordset. The
following KB article gives more information.

http://support.microsoft.com/kb/232144/en-us

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


When I use an sql statement to insert a record into a table, is there a way
to know what autonumber value was assigned so that I can update related
tables with that value in code?
 
is there a way to do this with DAO... I found some code previously posted
that was like this...

strsql = "select * from mytable where falso"
set rs = currentdb.openrecordset(strsql,dbopendynaset)

rs.addnew
'all required fields here
rs.update
NewID = rs!id
rs.close
......

but I'm getting an error at the statement newid = rs!id that there is no
current record (when the table starts out empty) even though it has added the
new record.

I looked at the article that you gave a link to but when I tried it I got a
reference library error, when I went to tools to find the ADODB Library I
could not find it. I'm new to access I've only use DAO recordsets.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top