Solved

Adding to rdoResultset

Posted on 1998-11-20
3
286 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
Comment Utility
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
Comment Utility
Thank you,
but where is my record pointer is pointing to?
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 50 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

743 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