Hello Everyone,
I have been searching for ways to prevent the autonumber field from increasing when a user decides he/she does not wish to enter a record.
I searched Bytes and I think I saw something that alluded to setting up two distinct tables (let's call them Table B and Table C). Table B is the one with one field and the field name is the same as the Autonumber field of the host table in question (let's call it Table A). Then Table C is the other field that represents the calculated difference?
I think what happens next is an append query is created to find the difference between the host, and then after that I am lost with how the calculated field passes the next sequential number without any gaps.
If this does not make sense, perhaps someone can provide a more coherent approach.
Can you assist?
Thanks in advance.
Qtip23
7 3351
What you can do is to stop using autonumber, and simply use Number, Long type for you field. Then when your about to save the record, you look for the max ID and simply add 1.
I think I would do this, in the forms beforeupdate event: - If Me.NewRecord Then
-
Me.txtID=DMax("ID","myTable")+1
-
End If
Smiley's advice is spot on! The very fact that you're concerned about 'missing' numbers shows that you shouldn't be using an Autonumber!
Autonumbers are intended to be used for one purpose and one purpose only, to provide a unique identifier for each record. Here's a post I've archived from a gentleman named John Vinson, MVP, explaining how Autonumbers work and giving even more scenarios where there will be gaps: When using Autonumber, do be aware that there will be gaps in the numbering - any record that's deleted will leave a gap; hitting <Esc> after starting a record will leave a gap; adding records using an Append query may leave a gap, often a huge one; replicating the database will make your invoice numbers random.
In short... it's best NOT to use Autonumbers for human consumption, and particularly not for consumption by accountants and auditors. Invoice sequences like 319, 321, 322, 385, 386, 221841246, -1083225152 make such people get very nervous.
Linq ;0)> @TheSmileyOne
Thanks @SmileyONe. it worked like a charm.
I wonder what would make me think I could chnage Autonumber feature...lol @Linq
You both have been very helpful!
Best,
Qtip23
Oh, one more thing. I actually put the code on the form's BeforeInsert event.
I do not want the user to be able to enter any number as I have this field locked on the form. Therefore, the next sequential ID is automatically generated.
Cheers,
Qtip23
If this is a multi-user app, as it sounds from your post, you need to place the code in the Form_BeforeUpda te event, as Smiley suggested!
When placed there, the ID number will be generated at the very last second before the record is saved, greatly decreasing the chance of two users' records generating the same ID.
Using the Form_BeforeInse rt event, on the other hand, generates the ID number the second a single character is entered in a new record, greatly increasing the chances of two records having the same ID number, and popping an error if the ID number is set to No Duplicates, as it should be.
For example, if using the Form_BeforeInse rt event, if UserA starts a record, the ID is generated, and before he/she completes the record, UserB starts a record; the same ID will be generated for both.
Linq ;0)>
@Linq duly noted ..just in case we plan to expand for distributed use,, although our team is very small (8 to 10). We plan to have a primary person perform data entry duties. A secondary person will fill in as necessary.
So I guess the form's Record Locks property - Edited Record- would not be capable to avoid the possible record conflict you're describing?
Qtip23
The record locks Edited Record, simply means that your current record is now locked, so that others cannot edit the same record at the same time.
If it is a new record it is not even visible to the other users yet, so the lock at this point has no relevance as far as I can see.
Here we are talking about accidentally assigning the same ID to what is intended to be 2 different records.
Is there any reason you are reluctant to put it in the forms BeforeUpdate event?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jan Hendrickx |
last post by:
Hi all,
I use (something like) following code to add new records to a database,
but it doesn't work!!!
I need to know the value of an AutoNumber-field when I add the record.
Why doesn't it work and how can I make it work???
I think it should be easy, but I can't figure it out!
|
by: Mike Wiseley |
last post by:
You can create a query in the SQL view that adds a new column to a table.
For example, to add a new text field named X10, you use the following
language:
Alter Table MyTargetTable1
Add Column X10 text;
Question: How can I make the new Column X10 be an AutoNumber field. The
following does NOT work:
|
by: ben.werdmuller |
last post by:
Hi,
Is there an easy way in ASP/VBscript to grab an autonumber (primary
key) field just after an SQL insert? This is probably easy, but I'm
stuck ..
Cheers.
|
by: S. van Beek |
last post by:
Dear reader,
By append a new record to a table I always expect the next higher value in
the range of the autonumber field.
But sometimes if I have deleted same records from a table the behaviour of
the autonumber field is changed.
|
by: marko |
last post by:
I would like my autonumber field to start at 100000. How can i do that?
| |
by: HS1 |
last post by:
Hello
I have a table in Access Database. This table has a AutoNumber field. I use
a DataGrid to show that table
When I insert a new record in for this table using a DataGrid, there is a
message that asks me to enter the value for this AutoNumber field. Why I
have to do that?
Could you please help
|
by: minjie |
last post by:
I need to upgrade a MS Access database (Version 2002) with a script
only, i.e., via SQL statement, not via Access GUI, and I'm having
trouble defining an AutoNumber field. I got an exception error when
running the follwoing (in a C++ program using ADO):
......
cmdStr = "CREATE TABLE mytab "
"( AutoNumber, "
" TEXT(50), "
"CONSTRAINT PRIMARY KEY ()); ";
|
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...
|
by: BMF |
last post by:
Howdy,
I am mainly a MySQL user but I have been playing with Access 07 a little bit recently. I created a database with 3 tables.
Table ID ---
userID -- AutoNumber
UserInfo - userID (linked to ID.userID
fname -- text
lname -- text
age -- number
|
by: Richard Sherratt |
last post by:
I've inherited a system that was designed by someone with no
understanding of database design. From the logical design point of
view, there is no logical design. The physical design is a nightmare.
e.g. there are no relationships between tables and foreign keys appear
to have been sprinkled at random like confetti. As an example, the
Employer - Employee - Contract - Expense hierarchy has EmployerID in
the Expense table. That's the...
|
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...
| |
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,...
|
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...
|
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |