Link to home
Start Free TrialLog in
Avatar of crossfire04
crossfire04Flag for United States of America

asked on

MSAccess Coding - How to get record ID of record just inserted

I have a function that I pass a record id to, this function copies the field values into a new record and does an insert.  I need to capture the new record's ID.  Can you help?
Function addnewrecord(testcasenbr)
 
    Dim db As DAO.Database
    Dim sSQL As String
    Dim rst
    Set db = DBEngine(0)(0)
    
    sSQL = " INSERT into tbl_Testcases " & "(tc_Name, tc_Desc) " & "SELECT tc_Name, tc_Desc " & _
             "FROM tbl_Testcases " & " WHERE tc_Id = " & testcasenbr & ";"
             
    db.Execute sSQL, dbFailOnError
    db.Close
 
End Function

Open in new window

SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial