ADO question

D

Dorian

If I am writing to a recordset with ADO and I have done a rs.Addnew and then
do not want to write the record, do I just not do an rs.Update or do I have
to do something to flush the pending record before I do another rs.Addnew.
Currently, I just omit the rs.Update but I am still getting the records
added to my output table.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
K

KC-Mass

Don't do a rs.Update until you have tested/validated the data and know you
want to add it.
Even if you don't do an update you've added the record but without values
 
A

AccessVandal via AccessMonster.com

You can use the connection method to rollback the inserted record. If you
using the recordset method……

Dim con as adodb.connection
Dim rst as new adodb.recordset

‘use the current db
Set con = currentproject.connect

‘open the table or query and with rst set to new

rst.open “Tableâ€, con

con.begintrans

with rst
.addnew
‘do whatever here to insert
‘……………….
‘fill up the table and wait for rollback or commit
.update
end with

If MsgBox("Save all changes?", vbYesNo) = vbYes Then
con.CommitTrans
Else
con.RollbackTrans
End If

con.Close
Set con = Nothing
Set rst = Nothing

Or you can use the connection execute method (air code)

With con
.begintrans
.execute strSQL, ‘the sql insert string

If MsgBox("Save all changes?", vbYesNo) = vbYes Then
con.CommitTrans
Else
con.RollbackTrans
End If
End with
 
J

JimBurke via AccessMonster.com

Just do an rs.cancel to cancel the new record.
If I am writing to a recordset with ADO and I have done a rs.Addnew and then
do not want to write the record, do I just not do an rs.Update or do I have
to do something to flush the pending record before I do another rs.Addnew.
Currently, I just omit the rs.Update but I am still getting the records
added to my output table.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 

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