Solved

prb: AddNew -> Update -> Delete

Posted on 1999-01-13
3
314 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 57
Put text in a picture ASP.NET C# 2 50
vb6 connector to mongodb 2 50
Add and format columns in vb6 7 47
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

15 Experts available now in Live!

Get 1:1 Help Now