473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Return AutoNumber Key

I'm struggling with a similar problem: a multi-user database, with "Autonumbered" primary key. When user 'a' adds a record, how does she retrive the actual PK entered? We can NOT assume it's the latest record added, because other users are adding records at nearly the same time.

How handy it'd be if dataadapter.insert would return a reliable vector of key(s) for the record(s) added.

Is there any other way? Or must I just do a selection on every field I've just entered? "Select * from MyTbl where fld1=MyFld1 and fld2 = MyFld2 and ... "

???

Thanks,
S
Jul 11 '07 #1
3 2003
NeoPa
32,556 Expert Mod 16PB
I'm afraid that, as this question is NOT the same as the original one (though I recognise there are similarities), then you need to post your question in its own new thread. It's perfectly acceptable to include a link to this thread if you feel it may help to clarify your question.

MODERATOR.
Jul 11 '07 #2
Both and advantage and a disadvantage of the 'autonumber' keys provided by MS Access and others is that they are assigned at the host database, not at the dataset. That means, as you have seen, that when you do a dataadapter.update you new records are added with the next autonumber, but you may not really know what that was. Even if you select the highest autonumber yet assigned, it may be one some other user has since assigned -- then there's always the case where you have configured your 'autonumber' key to be randomly, not sequentially assigned, so there's even less assurance that it's the 'highest' key.

What's a multi-user programmer to do? You might assign some alternate unique key (based on userid and timestamp, for instance) such that, once the new record is added, you can retrieve it by the timestamp you just put on it yourself -- then you will learn what the actual autonumber key is, if you still need it.

The ideal, to my way of thinking, would be for the database engine to return a table of new record key(s) for the record(s) added, when you do an insert or an update which adds new records. But then, they never seem to ask my opinion ;^))
Nov 10 '07 #3
NeoPa
32,556 Expert Mod 16PB
This discussion has been split away from the access message box/ VB code thread.

In fact it's an interesting point you make. Possibly the AddNew() method should return the value of any AutoNumber index that's created. Unfortunately (as is usually the case) things are not that simple. What about when adding a bunch of new records. The SQL can't return all the keys created.

The real answer is that you're trying to work with it in a way that it isn't designed to work. An automatically assigned field is there for supporting a table with unique keys. If it weren't created - how would you access the data you just added? That wouldn't change. That's not what it's there for.

Does that help?
Nov 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ilan Sebba | last post by:
I have a 'supertype' table with only one field: autonumber. Call this table the 'parent' table. There are two subtypes, 'androids' and 'martians'. Martian have only one thing in common: they give...
33
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and...
35
by: Traci | last post by:
If I have a table with an autonumber primary key and 100 records and I delete the last 50 records, the next record added would have a primary key of 101. Is there any way to have the primary key...
2
by: Megan | last post by:
Hi everybody- I have 2 tables, Hearings and Rulings. Both have primary keys called, CaseID, that are autonumbers. I don't want both tables to have the same autonumber. For example, if Hearings...
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
26
by: jimfortune | last post by:
Sometimes I use Autonumber fields for ID fields. Furthermore, sometimes I use those same fields in orderdetail type tables. So it's important in that case that once an autonumber key value is...
33
by: Steven Taylor | last post by:
Hope someone can help. This is half an Access question. The half I'm using is Access Xp as a backend data file. I'm using ODBC to connect to the data file. All commands are via SQL type...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
4
by: banderson | last post by:
Hello amazing vba writers, I am trying to make a combo box return a value based on a combo box selection. I have tried a number of the codes posted here and am still having problems. I think it is...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.