Solved

prb: AddNew -> Update -> Delete

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to mongodb 2 139
using web browser with BING 40 135
clicking a shape in a frame array vb6 3 48
Help me. 3 69
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

740 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