Solved

Adding to rdoResultset

Posted on 1998-11-20
3
302 Views
Last Modified: 2013-12-25
I have created a rdoResultset using VB 4.0 and filled the Resultset using select statement from SQL 6.0 server database.

When I want to add new record to a table I use the addnew method:

oRec.AddNew
oRec!IsBook = 1
oRec!Code = DoQuotes(ItemType)
oRec!Description = "Not set yet"
oRec.Update

mnItemTypeID = oRec!PKId ' this is the key
oRec.Close
Set oRec = Nothing

As you can see I need to retrieve the just entered and automatically assigned PKId. I expected the current record pointer to point to the newly created record, but it points to the first record in the recordset instead. Does the rdo work say way as DAO? What is my solution? I cant issue oRec.movelast due to multi-user limitation.
Please share your experience with RDO.
Thank you


0
Comment
Question by:misha051797
  • 2
3 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1497759
The .AddNew should init the key. Try grabbing it prior to the .Update. .Update commits the record in memory to disk. Any Automatic fields should be created when the .AddNew fires, NOT when the .Update triggers.
0
 

Author Comment

by:misha051797
ID: 1497760
Thank you,
but where is my record pointer is pointing to?
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 50 total points
ID: 1497761
Depends. During the interval between the .AddNew and .Update it should be pointing to the record you're building in memory. After the .Update I think it's undefined until you reposition the pointer.

You gotta remember that in Access type databases the record pointers and such are much less important than in flat file database like dBase/FoxPro. The record is referenced more by it's INDEX than by it's record number. This is one of the reasons that it is so *hard* to get record numbers, they're really meaningless in the context of an Access data structure. Once you get over this hump you'll find that the data is much easier to manipulate, why should *you* have to worry about what # the record is as long the the *program* gets the right data! It's actually *simpler* to just say "gimme *this*" and let the database worry about where it is.

When you do a SELECT * FROM you're grooming a fresh data set every time. The .MoveNext moves thru your selected data in the order that the SELECT returned it. This means that you don't have to worry about which is which.

If you need to return to a specific record use BOOKMARK to note where you were, but remember that the BOOKMARK will be invalid after the next SELECT statement.

M

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

808 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