on error goto errh
oRS.addnew
oRs.fields("id") = 2 ' this will error later on
oRs.update
exit sub
errh
msgbox err.description
oRs.cancelupdate
When I try editing an existing record and set ID =2 it generates an
error -Cannot insert duplicate key row in object 'TABLE' with unique
index 'CK_#########'.
I then run oRS.cancelupdate and the ID value changes back to what it
was..
If however I'm adding a new record and try cancelupdate after the
attempted update method fails. I get
"Multiple-step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done."
BUT the record is still in the recordset. I cannot requery or close
the recorset only way around it is to set oRS = new adodb.recordset
and redo query.
Errors
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert duplicate
key row in object 'TABLE' with unique index 'CK_#########'.
[Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been
terminated.
[Microsoft][ODBC SQL Server Driver]Invalid cursor position
Multiple-step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done.
Then after calling cancelupdate.
Operation was canceled.
1
Sorry realised after posting I was using ODBC - rather than OLEDB...