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.gcnProgramManageme nt, adOpenStatic , adLockOptimistic
'Add field values to records
mrsSession![SessionTypeId] = vSessionTypeTemp
mrsSession![Title] = txtTitle.Text
mrsSession![Date] = vDateTemp
mrsSession![Days] = txtDays.Text
frmMain.gcnProgramManageme nt.BeginTr ans
mrsSession.Update
frmMain.gcnProgramManageme nt.CommitT rans
mrsSession.Delete
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.gcnProgramManageme
'Add field values to records
mrsSession![SessionTypeId]
mrsSession![Title] = txtTitle.Text
mrsSession![Date] = vDateTemp
mrsSession![Days] = txtDays.Text
frmMain.gcnProgramManageme
mrsSession.Update
frmMain.gcnProgramManageme
mrsSession.Delete
I don't see an AddNew statement ???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.gcnProgramManageme nt.BeginTr ans
mrsSession.Update
frmMain.gcnProgramManageme nt.CommitT rans
mrsSession.Delete
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]
mrsSession![Title] = txtTitle.Text
mrsSession![Date] = vDateTemp
mrsSession![Days] = txtDays.Text
frmMain.gcnProgramManageme
mrsSession.Update
frmMain.gcnProgramManageme
mrsSession.Delete