ADO AddNew method not picking up last record

D

Dom

I'm using ADO and trying to Add a new record to a table using the AddNew
Method. The entire recordset (about 2,400 records) is being successfully
added with the exception of the LAST record.
An example of some of the code I'm using is as follows -

cnAdd.open cnString

cnAdd.BeginTrans

rsCopy.open strSQL, etc etc

Do Until rsCopy.EOF

strSQL = "SELECT Item FROM tbl WHERE Name = '" & rsCopy!name & "'"

rsRule.Open strSQL, cnAdd, adOpenDynamic, adLockOptimistic

Do Until RSRule.EOF

rsRule.Addnew
rsRule!Item = "Item"

Loop

rsrule.close

Loop

cnAdd.CommitTrans
cnadd.close
(There is error trapping which will RollBack the transaction.)

I've tested the code and the last item is definitely there when I step
through the code but it gets lost once it leaves the loop.

So, is there something obvious I'm missing?
 
K

Klatuu

Dom,
This is not an uncommon problem. RsCopy will alway hit EOF with one row
left in the buller. All you need to do is copy your:
rsRule.Addnew
rsRule!Item = "Item"
to right after the second Loop statment. That will pick up the last row.
What I don't understand is why you need the second loop for rsRule. As you
are adding rows to it, EOF becomes irrelevant.
 
D

Dom

Thanks for that...
Sorry about this but my example was wrong. The inner loop doesn't exist.
Would your fix still work in theory?
Thanks
Dom
 
K

Klatuu

Yes, it will still work without the inner loop

Dom said:
Thanks for that...
Sorry about this but my example was wrong. The inner loop doesn't exist.
Would your fix still work in theory?
Thanks
Dom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top