Solved

Adding to rdoResultset

Posted on 1998-11-20
3
294 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

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

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

910 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

20 Experts available now in Live!

Get 1:1 Help Now