473,830 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

use of autonumber

Our database has a field called 'Card' which records the transaction
reference number. This is generated as an autonumber. Not the best way at
all - I know, having picked this up in the last few months.

We do not want to use 7 numbers for this, and would like to know if we can
generate the Card number by 'picking up' any of the 'missing' Card
autonumbers in the Card field? (autonumber having missed an awful lot of
insertions)...

I guess a bit of code that looks at the Card column, and picks up one of the
non-sequential (missing!) numbers, and inserts that into the new record Card
field..?

--
Thanks,
Lap

Nov 12 '05 #1
5 1801
If you want your numbers to be meaningful (e.g. sequential), don't use
autonumber.
Change to a Long Integer, and calculate the value you want explicitly, e.g.
by using DLookup().

HTH
- Turtle

"Lapchien" <bl**@blar.tv > wrote in message
news:10******** *******@ananke. eclipse.net.uk. ..
Our database has a field called 'Card' which records the transaction
reference number. This is generated as an autonumber. Not the best way at all - I know, having picked this up in the last few months.

We do not want to use 7 numbers for this, and would like to know if we can
generate the Card number by 'picking up' any of the 'missing' Card
autonumbers in the Card field? (autonumber having missed an awful lot of
insertions)...

I guess a bit of code that looks at the Card column, and picks up one of the non-sequential (missing!) numbers, and inserts that into the new record Card field..?

--
Thanks,
Lap

Nov 12 '05 #2
Yes, no question that is what we require. Can you give us some of the
mechanics needed (code?) to lookup and return the 'missing' sequential
numbers in the table and return those as the value we require for 'Card'?
"MacDermott " <ma********@nos pam.com> wrote in message
news:H3******** **********@news read2.news.atl. earthlink.net.. .
If you want your numbers to be meaningful (e.g. sequential), don't use
autonumber.
Change to a Long Integer, and calculate the value you want explicitly, e.g. by using DLookup().

HTH
- Turtle

"Lapchien" <bl**@blar.tv > wrote in message
news:10******** *******@ananke. eclipse.net.uk. ..
Our database has a field called 'Card' which records the transaction
reference number. This is generated as an autonumber. Not the best way

at
all - I know, having picked this up in the last few months.

We do not want to use 7 numbers for this, and would like to know if we can generate the Card number by 'picking up' any of the 'missing' Card
autonumbers in the Card field? (autonumber having missed an awful lot of
insertions)...

I guess a bit of code that looks at the Card column, and picks up one of

the
non-sequential (missing!) numbers, and inserts that into the new record

Card
field..?

--
Thanks,
Lap


Nov 12 '05 #3
BTW they numbers do not have to be sequential - we don't view card number
666660 as newer than 666659...

"MacDermott " <ma********@nos pam.com> wrote in message
news:H3******** **********@news read2.news.atl. earthlink.net.. .
If you want your numbers to be meaningful (e.g. sequential), don't use
autonumber.
Change to a Long Integer, and calculate the value you want explicitly, e.g. by using DLookup().

HTH
- Turtle

"Lapchien" <bl**@blar.tv > wrote in message
news:10******** *******@ananke. eclipse.net.uk. ..
Our database has a field called 'Card' which records the transaction
reference number. This is generated as an autonumber. Not the best way

at
all - I know, having picked this up in the last few months.

We do not want to use 7 numbers for this, and would like to know if we can generate the Card number by 'picking up' any of the 'missing' Card
autonumbers in the Card field? (autonumber having missed an awful lot of
insertions)...

I guess a bit of code that looks at the Card column, and picks up one of

the
non-sequential (missing!) numbers, and inserts that into the new record

Card
field..?

--
Thanks,
Lap


Nov 12 '05 #4
On Thu, 11 Dec 2003 07:26:45 -0000, "Lapchien" <bl**@blar.tv > wrote:

If you want to set a value, change your autonumber to longint.

I don't think there is a SQL Statement that would find missing
numbers, unless you have another table with all 6-digit numbers. So
you write some DAO code like this (off the top of my head).
Essentially you loop over the card numbers checking for a gap in the
numbers.

public function GetNextCard() as long
dim lngCardPrev as long
dim lngCardNew as long
dim db as dao.database
dim rs as dao.recordset
set db=currentdb
'NOTE: Assuming Card is the Primary Key, so rs will be ordered by
Card. If not, use a query with an OrderBy clause.
'NOTE2: This needs work if table can ever have 0 or 1 row.
set rs=db.openrecor dset("MyTable", dbOpenSnapshot)
lngCardPrev=rs! Card
lngCardNew=0
rs.movenext
do while not rs.eof
if rs!Card=lngCard Prev+1 then
'not a gap
rs.movenext
else
'gap found
lngCardNew=rs!C ard
exit do
end if
loop
if lngCardNew=0 then
'found EOF before we found a gap. Use next no.
lngCardNew=lngC ardPrev+1
end if
rs.close
set rs=nothing
set db=nothing
GetNextCard=lng CardNew

-Tom.

Our database has a field called 'Card' which records the transaction
reference number. This is generated as an autonumber. Not the best way at
all - I know, having picked this up in the last few months.

We do not want to use 7 numbers for this, and would like to know if we can
generate the Card number by 'picking up' any of the 'missing' Card
autonumbers in the Card field? (autonumber having missed an awful lot of
insertions). ..

I guess a bit of code that looks at the Card column, and picks up one of the
non-sequential (missing!) numbers, and inserts that into the new record Card
field..?


Nov 12 '05 #5
On Thu, 11 Dec 2003 07:27:43 -0700, Tom van Stiphout
<to*****@no.spa m.cox.net> wrote:

Oops, after rs.movenext, add this line:
lngCardPrev = rs!Card

-Tom.
On Thu, 11 Dec 2003 07:26:45 -0000, "Lapchien" <bl**@blar.tv > wrote:

If you want to set a value, change your autonumber to longint.

I don't think there is a SQL Statement that would find missing
numbers, unless you have another table with all 6-digit numbers. So
you write some DAO code like this (off the top of my head).
Essentially you loop over the card numbers checking for a gap in the
numbers.

public function GetNextCard() as long
dim lngCardPrev as long
dim lngCardNew as long
dim db as dao.database
dim rs as dao.recordset
set db=currentdb
'NOTE: Assuming Card is the Primary Key, so rs will be ordered by
Card. If not, use a query with an OrderBy clause.
'NOTE2: This needs work if table can ever have 0 or 1 row.
set rs=db.openrecor dset("MyTable", dbOpenSnapshot)
lngCardPrev=rs !Card
lngCardNew=0
rs.movenext
do while not rs.eof
if rs!Card=lngCard Prev+1 then
'not a gap
rs.movenext
else
'gap found
lngCardNew=rs!C ard
exit do
end if
loop
if lngCardNew=0 then
'found EOF before we found a gap. Use next no.
lngCardNew=lngC ardPrev+1
end if
rs.close
set rs=nothing
set db=nothing
GetNextCard=ln gCardNew

-Tom.

Our database has a field called 'Card' which records the transaction
reference number. This is generated as an autonumber. Not the best way at
all - I know, having picked this up in the last few months.

We do not want to use 7 numbers for this, and would like to know if we can
generate the Card number by 'picking up' any of the 'missing' Card
autonumbers in the Card field? (autonumber having missed an awful lot of
insertions).. .

I guess a bit of code that looks at the Card column, and picks up one of the
non-sequential (missing!) numbers, and inserts that into the new record Card
field..?


Nov 12 '05 #6

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

Similar topics

3
4777
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
4329
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...
35
7287
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 start at 51 after the last 50 records are deleted? Thanks! Traci
4
5172
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 4,294,967,295. Suppose the PRIMARY key data type is set to "RANDOM" AutoNumber. Suppose an application (a) successfully INSERTS "X" records, then (b) successfully DELETES "Y" records (X >= Y), then
26
3834
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...
8
15973
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
4505
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
3963
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
11239
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...
6
11773
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 contents of the form is inserted into the MS Access database. The Customer table in the database already has 30 records (with CustomerIDs 1 - 30) in it (from when the database was first created). The CustomerID field in the database is an...
0
9791
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
9642
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
10771
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
9313
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
7745
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
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
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...
1
4411
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
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.