I rewrote the function like this:
Function InsertRecord(dbConnectionString, tableName, primaryKeyName, fieldNames, fieldValues)
Dim cn,rs,ID
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
cn.Open dbConnectionString
cn.BeginTrans
rs.Open tableName, cn, 1, 3, 2 'adOpenKeyset, adLockOptimistic, adCmdTable
rs.AddNew fieldNames, fieldValues
rs.Update
' Fixed Bug:
' reading from a MySQL database, the following code is not returning the last AUTOINCREMENT PrimaryKey ID
' rs.MoveLast
' ID = rs.Fields(primaryKeyName).Value
rs.Close
Dim sql : sql = "SELECT * FROM " & tableName & " ORDER BY " & primaryKeyName & " DESC"
Set rs = cn.Execute(sql)
ID = rs.Fields(primaryKeyName).Value
rs.Close
Set rs = Nothing
cn.CommitTrans
cn.Close
Set cn = Nothing
If Err.Number = 0 Then
InsertRecord = ID
Else
InsertRecord = Nothing
End If
End Function