Problem with Insert into Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • usiddiqi
    New Member
    • Jul 2007
    • 1

    #1

    Problem with Insert into Query

    Hi,

    Im using a querydef object for inserting into a table. But in that table there is a automated genereated primary key. How can I get that key once the recored successfully inserted into the table?

    Here is my code:

    Dim qry As QueryDef
    str = "INSERT INTO Vendor (vendor) VALUES ('" & VendorList.Valu e & "')"
    qry.SQL str
    qry.Execute

    So in the vendor table there is a column "vendorID", which is a automated generated key. How can i get that after the above code? Any help or guidence will be greatly appreciated.

    regards,
    Umer
  • danp129
    Recognized Expert Contributor
    • Jul 2006
    • 323

    #2
    Originally posted by usiddiqi
    Hi,

    Im using a querydef object for inserting into a table. But in that table there is a automated genereated primary key. How can I get that key once the recored successfully inserted into the table?

    Here is my code:

    Dim qry As QueryDef
    str = "INSERT INTO Vendor (vendor) VALUES ('" & VendorList.Valu e & "')"
    qry.SQL str
    qry.Execute

    So in the vendor table there is a column "vendorID", which is a automated generated key. How can i get that after the above code? Any help or guidence will be greatly appreciated.

    regards,
    Umer
    If it's Ms SQL Server you could use something like this:

    Code:
    Dim vendorID
    rs.Open "SELECT @@IDENTITY AS id", adoCon
    vendorID=rs("id")
    rs.Close
    Dunno about other databases.

    Comment

    Working...