473,666 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Autonumber of new record

Is there a way to get the autonumber of a newly inserted record?

I am working with unbound forms, and using an append query to insert a
record into a table. I am then using a select query that returns the max ID
(the autonumber field) of the table. This gives me the correct number.
However, could this go wrong in a multi-user environment. I insert a
record, and say it gets ID 10, but before (even thoug it is a split second)
I read the max value, someone else inserts a record with ID 11.

What I need is a way to get the nubmer of the record I have just inserted.

Thanks
Nov 13 '05 #1
2 3827
Hey!

I have an idea: Don't allocate the running number on form open-allocate the
running number on saving. You can do this with runningnumber = "select
max([Running Number]) from Table" + 1 (hope the syntax is correct). So you
have always the actual number. This also works in a network-client
database! I hope I help you - when you have problems, feel free to write!

Ps: Sorry for my bad english, I hope you know what I mean!

best wishes Philipp

Ok i think there is a way. When you write your record in the table, before
you
"M Fisher" <m.******@uku.c o.uk> schrieb im Newsbeitrag
news:xs******** *******@newsfe5-win.ntli.net...
Is there a way to get the autonumber of a newly inserted record?

I am working with unbound forms, and using an append query to insert a
record into a table. I am then using a select query that returns the max ID (the autonumber field) of the table. This gives me the correct number.
However, could this go wrong in a multi-user environment. I insert a
record, and say it gets ID 10, but before (even thoug it is a split second) I read the max value, someone else inserts a record with ID 11.

What I need is a way to get the nubmer of the record I have just inserted.

Thanks

Nov 13 '05 #2
Indeed in a multi-user environment, the max value (autonumber ID) is not always *your* inserted record.

You will need an extra field UserID in YourTable. This will represent the person that inserted the record.
*Your* max value now is something like: Select Max(ID) FROM YourTable Where UserID = YourUserID

--
Hope this helps
Arno R

"M Fisher" <m.******@uku.c o.uk> schreef in bericht news:xs******** *******@newsfe5-win.ntli.net...
Is there a way to get the autonumber of a newly inserted record?

I am working with unbound forms, and using an append query to insert a
record into a table. I am then using a select query that returns the max ID
(the autonumber field) of the table. This gives me the correct number.
However, could this go wrong in a multi-user environment. I insert a
record, and say it gets ID 10, but before (even thoug it is a split second)
I read the max value, someone else inserts a record with ID 11.

What I need is a way to get the nubmer of the record I have just inserted.

Thanks

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2864
by: Charles Robinson III | last post by:
The AutoNumber sequence in my database is currently formatted as '000000'. When a new record is created, the AutoNumber would go from 000001, 000002, 000003 and so on. I want to track via AutoNumber the year each record was created. Basically, if a record was entered in 2003, the AutoNumber would look something like 03-000001 and then 03-000002, and so on. When a record would be entered in 2004, the AutoNumber would look something...
3
4766
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 birth to identical mules. So each android and a martian have primary key which is a foreign key to the parent table. Now, I want to insert a new record in 'android' or 'martian'. This can be done easily using MS-Access forms. But I want to do...
33
4280
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 setting default value to a UDF that manages the auto-numbering. Access won't take a UDF as a default value. Okay, I'll use SQL WITHOUT any aggregate functions, for the default value. Access won't do that either. Okay, I create a second...
26
3804
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 assigned to a record that it doesn't change. Occasionally I find that due to corruption or an accidental deletion and restore of a record from a backup the autonumber field needs to be tidied up. So when I create (through AddNew) the autonumber...
4
7741
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query, but I can't update record in query or in form. I believe the problem is due to the source query. In source query, there is a filter to show the incomplete record ("is null" in delivery date)], but I need to re-use the job no. if the job is...
8
15961
by: petebeatty | last post by:
I have created a SQL string the properly inserts a record in the table. However, the insert does not occur at the end of the table. Instead it inserts a record after the last record that I viewed. This would be OK, except it assigns a autonumber to be one greater than the last viewed record. This causes a duplicate autonumber. I know I can change the autonumber index (Primary Key) to not allow duplicates. How can I force the insert...
11
4485
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 AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
1
3949
by: gtwannabe | last post by:
I'm having a problem with a form that uses AutoNumber as the primary key. I have an Abort button to delete the current record and close the form. If AutoNumber is assigned, the code executes a SQL statement that deletes the current record. I need to be able to detect when AutoNumber is unassigned (a new blank record) so that I can simply close the form without running the SQL delete statement. Unfortunately, no tests I can think of...
9
11223
by: Tom_F | last post by:
To comp.databases.ms-access -- I just discovered, to my more than mild dismay, that some tables in my Microsoft Access 2003 database have duplicate numbers in the "AutoNumber" field. (Field Size is set to "Long Integer", and New Values is set to "Increment".) I know that an old version of the Jet database engine can cause this problem, but my version of msjet40.dll is 4.0.8618.0, which is supposedly bug-free in this respect. I am...
4
38377
by: Lyn | last post by:
Hi, Is there an "easy" way to write a full record (all fields) using "INSERT INTO..." into a table which has an AutoNumber field? Normally, to write a full new record I would use: INSERT INTO VALUES (Value1, Value2, ...); If (say) the first field (Value1) is an AutoNumber, what value can you put that will preserve the auto-increment function?
0
8445
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.