Link to home
Start Free TrialLog in
Avatar of gautschi
gautschi

asked on

prb: AddNew -> Update -> Delete

I wanna add a new row to recordset... after that i wanna delete the same record.
I tried:
rs.AddNew
rs.Update
rs.Delete

But somehow it doesn't work :(
(Error Message: Run-time error '-2147217864 (80040e38)':
The specified row could not be located for updating: Some values may have been changed sine it was last read)
Doesn't "Update" refreshs my recordset too?`
btw: I would like that the NewAdded Recordset stays at the _last_ position (before deleting)

why doesn't it works? and how can i fix it?

------------------- some code --------------------------
'gcnProgramManagement is the connection  
    Dim mrsSession As New ADODB.Recordset

    mrsSession.CursorLocation = adUseClient
         
    mrsSession.Open vSQLSelect, frmMain.gcnProgramManagement, adOpenStatic , adLockOptimistic

    'Add field values to records
    mrsSession![SessionTypeId] = vSessionTypeTemp
    mrsSession![Title] = txtTitle.Text
    mrsSession![Date] = vDateTemp
    mrsSession![Days] = txtDays.Text
   
    frmMain.gcnProgramManagement.BeginTrans
    mrsSession.Update
    frmMain.gcnProgramManagement.CommitTrans

    mrsSession.Delete
Avatar of tomook
tomook

I don't see an AddNew statement ???
ASKER CERTIFIED SOLUTION
Avatar of vspeter
vspeter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gautschi

ASKER

vspeter: The probleme is that i open just one connection and i don't close it anymore (till the user will close the program) - same with the recordset. so i can't add it (BeginTrans) before it :(
btw: i've read that you shouldn't add the BeginTrans at the begin of the recordset - you sould add it just before the .Update

tomook: ok.. here's the .AddNew :)
   
    mrsSession.AddNew

    'Add field values to records
    mrsSession![SessionTypeId] = vSessionTypeTemp
    mrsSession![Title] = txtTitle.Text
    mrsSession![Date] = vDateTemp
    mrsSession![Days] = txtDays.Text
     
    frmMain.gcnProgramManagement.BeginTrans
    mrsSession.Update
    frmMain.gcnProgramManagement.CommitTrans

    mrsSession.Delete