?
Solved

prb: AddNew -> Update -> Delete

Posted on 1999-01-13
3
Medium Priority
?
326 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
ID: 1498979
I don't see an AddNew statement ???
0
 
LVL 2

Accepted Solution

by:
vspeter earned 200 total points
ID: 1498980
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
ID: 1498981
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

809 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