Solved

prb: AddNew -> Update -> Delete

Posted on 1999-01-13
3
313 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:gautschi
3 Comments
 
LVL 4

Expert Comment

by:tomook
Comment Utility
I don't see an AddNew statement ???
0
 
LVL 2

Accepted Solution

by:
vspeter earned 100 total points
Comment Utility
Having understand that you've only put SOME CODE there.

The problem could be because of where place frmMain.gcnProgramManagement.BeginTrans statement.

I would put it at the begining, even before you start using the connection handle to set other properties.

Also the frmMain.gcnProgramManagement.CommitTrans would be the last statement to be execute for any thing got to do with the connection handle.

Let me know how you go

Cheers,
0
 

Author Comment

by:gautschi
Comment Utility
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

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now