tags:

views:

374

answers:

1

I have the following code to insert items into a MySQL database from an Excel form.

Set rs = New ADODB.Recordset
ConnectDB
With wsWorkBook
    strSQL = "INSERT INTO work_order (job_status, job_description, system_id) VALUES ....;"
    rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic
    ' word_order.id
End With

How can I get the last insert id of that line, which is in the work_order.id column?

A: 

Try using the LAST_INSERT_ID() - operator in a following SQL-Statement:

SELECT LAST_INSERT_ID();
Björn
code example would be fine. I'm not fluent in ADODB yet.
adobina
After your code example, just call another SQL-Statement, only this time not an INSERT-Command, but a Select-Statement...strSQL = "SELECT LAST_INSERT_ID();"...then do whatever you do to execute that query and retrieve that value.
Björn