M.A
M.A

Reputation: 273

VB6 Retrieve the last autoincremented ID and Update the record again

I have a piece of code that is inserting a new row into a table and then retrieving the SerialNo, updates the ReferenceNo column using the SerialNo and then again updates the database.

However on the second update I get an error of: Row cannot be located for updating. Some values may have been changed since it was last read.

Code looks like this

DataEnvironment1.rsAddNewMsg.Open

With DataEnvironment1.rsAddNewMsg

.Field1 ="mpla"
.Field2 ="mpla"
....

.Update

.ReferenceNo = "Mpla" + SerialNo

.Update

DataEnvironment1.rsAddNewMsg.Close

The error occurs on the second update.

Upvotes: 0

Views: 849

Answers (2)

M.A
M.A

Reputation: 273

After two days struggling with this error I finally found out the problem. Problem was a constraint I had on the table in order to default another field (irrelevant) to 'N'. After Disabling this Constraint my code worked like a charm! :)

youpiiii!

Just for my records in order to manage to find the cause I simulate the error with a small new table, having the identity on it. During testing I notice that updates were working on that one. So Update part was ok. Thus I took a part of my normal code separate it and test by chaning properties on the table until to find the cause.

Thanks you however for any help :)

Upvotes: 1

Simon
Simon

Reputation: 6152

You probably need to re-open the recordset to pickup your changes. You could also try opening a Dynamic type recordset which might better reflect the updates to the data. I think you'll be opening a forward-only recordset by default.

Sorry, it's been a long while since I last used ADO so I'm a little rusty!

Upvotes: 0

Related Questions