Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    9

    Unanswered: insert statement

    is there any "last insert ID" when saving in access?
    i tried it in VB.NET when saving data in a form where there are two tables link through a certain "ClientID"

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    maybe!

    experiment with something like the following:

    dim strSQL as string
    dim rst as DAO.recordset
    strSQL = "SELECT @@identity FROM mytable"
    set rst = CurrentDb.OpenRecordset(strSQL)
    msgbox "Last insert in mytable was at " & rst.Fields(0)
    set rst = nothing

    code seems to work in simple situations, but i don't use it and have no idea how robust it is.
    my preferred approach would be to manually insert the ID.
    i posted one possible route here.

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Feb 2009
    Posts
    9
    the table i'm saving is link to another table by a "ClientID". i need to save the tables ClientID(PK) into the other table(FK), so i need to use something like last insert ID

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    is it my writing skills or your reading skills (BTW i'm famous for lousy reading skills so don't take this too hard)?

    control your own life: take possession of the new ID by "manually" INSERTing it and then you can do whatever you want with it in as many tables as you can find.

    izy
    currently using SS 2008R2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •