473,465 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to get deleted autonumber

vs2k8
13 New Member
Hello guys,

I have this field name OrdNum which is AutoNumber, my issue is whenever I cancel or undo the record I entered I miss my OrdNum sequence, like I had OrdNum 7002, I canceled the record when I tried to enter the number it starts with 7003 instead of 7001 so now I have 7001 then 7003, how I can achieve the missed number.
My table name is OrdEnter
My Field name is OrdNum

Thanks in advance.

-visa
Jul 9 '08 #1
3 1831
missinglinq
3,532 Recognized Expert Specialist
You can't! Autonumbers are intended to be used for one purpose and only one purpose, to provide a unique identifier for each record. Here's a psot I've archived from a gentleman named John Vinson, MVP, explaining how autonumbers work:

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.
For the kind of field you're using, OrdNum, you need to use an auto-incrementing number hack such as one of these.

The first code here would be for an IDNumber that is defined in the table as Text datatype. "Number" fields that aren't used for math really should be defined as Text.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3.   If RecordsetClone.RecordCount = 0 Then
  4.    Me.IDNumber = "1"
  5.   Else
  6.    Me.IDNumber = DMax("val([IDNumber])", "YourTableName") + 1
  7.   End If
  8. End If
  9. End Sub
  10.  
If you insist on using a Numerical field:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3.   If RecordsetClone.RecordCount = 0 Then
  4.    Me.IDNumber = 1
  5.   Else
  6.    Me.IDNumber = DMax("[IDNum]", "YourTableName") + 1
  7.   End If
  8. End If
  9. End Sub
Welcome to Bytes!

Linq ;0)>
Jul 10 '08 #2
vs2k8
13 New Member
Thanks a lot, it worked for me.

-visa
Jul 10 '08 #3
missinglinq
3,532 Recognized Expert Specialist
Glad we could help!

Linq ;0)>
Jul 11 '08 #4

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

Similar topics

4
by: Scott Kinney | last post by:
I have an inventory database. I want to delete out-of-stock items from the main database, but keep them in a separate table so that I can reference data about them. I created a copy of the item...
10
by: DaveDiego | last post by:
I've had a user delete one of the client records, I do have a version of the DB with all records intact before the deletion occured. Whats the best approach to getting all the related records in...
0
by: Nom De Plume | last post by:
I have a set of tables in SQL Server, which, when I link in Access, I get all the fields displayed as #Deleted when I look in table view or the output of a query. However, when I walk the...
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...
3
by: Prakash | last post by:
Below is my code to delete a record in a continuous form. I can't figure out any reason but sometimes (another) record gets deleted instead of where the record pointer is positioned. Small table...
1
by: KC | last post by:
I am using Access 2002, with a database template from MS Office. The Orders Management Database. I have tweaked this for use with our company. It is a small database with close to a 1000 records...
12
by: magmike | last post by:
Accidentally deleted a record. Anyway to get it back? If not, I know the ID number - which is an autonumber field. Because of the related data from other tables, would I be able to create a new...
2
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....
1
by: Rob | last post by:
Is it possible to prevent a row from being deleted in a table. I want to arrange a new table with an autonumbered primary key that will form part of a set of sequential serial numbers. I want to...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...
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,...
0
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...
0
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...
0
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 ...

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.