473,473 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Gaps in a Sequence Number

Hi,

I'm in need of some expert help in sorting a numerical/alphanumerical
employee ID field (5&6 characters in length).

Also seperating the alphanumerical IDs and finding the gaps in the sequence
numbers (These numbers will always begin with a "C"). Reason for this is to
assign an unused alphanumeric number to a employee. Therefore only one
unused alphanumeric number needs to be viewed at a time. The original
database designer used the... DoCmd.GoToRecord , , acLast to locate the
last record. It has become useless since I am at C99999. It is a 2003
database. Can this be done with Visual Basics? I will be glad to forward a
sample of the database.

Thanks
Jaka
Example:

Table: Employee
Field: EmployeeID

C1345
C0001
45573
100023
C1356
C1347
C1349

Sorted data;
C0001
C1345
C1347
C1349
C1356

Individual gap result;
C0002
C0003
C0004 etc....

Jun 27 '08 #1
2 3370
jaka wrote:
Hi,

I'm in need of some expert help in sorting a numerical/alphanumerical
employee ID field (5&6 characters in length).

Also seperating the alphanumerical IDs and finding the gaps in the sequence
numbers (These numbers will always begin with a "C"). Reason for this is to
assign an unused alphanumeric number to a employee. Therefore only one
unused alphanumeric number needs to be viewed at a time. The original
database designer used the... DoCmd.GoToRecord , , acLast to locate the
last record. It has become useless since I am at C99999. It is a 2003
database. Can this be done with Visual Basics? I will be glad to forward a
sample of the database.

Thanks
Jaka
Example:

Table: Employee
Field: EmployeeID

C1345
C0001
45573
100023
C1356
C1347
C1349

Sorted data;
C0001
C1345
C1347
C1349
C1356

Individual gap result;
C0002
C0003
C0004 etc....
The best way to sort a char/number field is to zero pad the numbers.
Otherwise you might get 1,10,100,2,20,200... It appears you do have it
zero padded so the sort should be OK.

The question is....is this id/key field linked to other records in other
tables? For example, let's say the current number is C1345. It really
should be C0004. If you have other records in say an orders table with
C1345, you would need to update all references of C1345 to C0004 in all
tables that use your key field.

Before you make ANY changes make sure you have a backup copy!!!!!

You could try this...if the Emp table doesn't have an autonumber. Open
the table in design mode and create a new field; NewNum type autonumber.
and NewEmpID type Text. Save it. You should now have a sequential list
of numbers in NewNum. With an update query you could update NewEmpID to
"C" & Right("00000" & NewNum,5)
Now you'll have a sequential list in the emp file.

There's a promblem with autonumbers in this type of situation. If you
open a record, start something, and then leave without saving the record
you'll have a skip between autonumbers.

So you need to change the autonumber to Numeric/longint so you don't get
gaps. So change NewNum to type Numeric.

For the most part, concatenating alph to numeric to create a key is poor
design, afaic. If you don't want breaks, you should create the key
when the record is saved, not when created. You can use DMax to get the
max number of NewNum and add 1 to it to avoid breaks. Ex:
NewEmpID = "C" & Right("00000" & (Dmax(NewNum)+1),5)
Also, once you update your table and get your dataentry correct for
creating the key you need to change NewEmpID to your old EmpID.

If your system has been in use for a while and other tables use your
current numbers, you have a problem that's not as easy to correct by
simply updating the number/key. Any help you get you should be willing
to pay for.

Juanica
http://www.youtube.com/watch?v=EAVJf5WMIEQ

Jun 27 '08 #2
Hi,

I appreciate your assistance. I ended using this statement to give me the
"one" unused number.

SELECT TOP 1 [EmployeeID]+1 AS [Unused Contractor Number]
FROM Employee
WHERE (((Exists (SELECT 0 FROM Employee AS i WHERE i.EmployeeID = Employee.
EmployeeID + 1))=False));

Though this barely fits what I wanted, it will work for now until I can
figure out something more robust.

Jaka
Salad wrote:
>Hi,
[quoted text clipped - 37 lines]
>C0003
C0004 etc....

The best way to sort a char/number field is to zero pad the numbers.
Otherwise you might get 1,10,100,2,20,200... It appears you do have it
zero padded so the sort should be OK.

The question is....is this id/key field linked to other records in other
tables? For example, let's say the current number is C1345. It really
should be C0004. If you have other records in say an orders table with
C1345, you would need to update all references of C1345 to C0004 in all
tables that use your key field.

Before you make ANY changes make sure you have a backup copy!!!!!

You could try this...if the Emp table doesn't have an autonumber. Open
the table in design mode and create a new field; NewNum type autonumber.
and NewEmpID type Text. Save it. You should now have a sequential list
of numbers in NewNum. With an update query you could update NewEmpID to
"C" & Right("00000" & NewNum,5)
Now you'll have a sequential list in the emp file.

There's a promblem with autonumbers in this type of situation. If you
open a record, start something, and then leave without saving the record
you'll have a skip between autonumbers.

So you need to change the autonumber to Numeric/longint so you don't get
gaps. So change NewNum to type Numeric.

For the most part, concatenating alph to numeric to create a key is poor
design, afaic. If you don't want breaks, you should create the key
when the record is saved, not when created. You can use DMax to get the
max number of NewNum and add 1 to it to avoid breaks. Ex:
NewEmpID = "C" & Right("00000" & (Dmax(NewNum)+1),5)
Also, once you update your table and get your dataentry correct for
creating the key you need to change NewEmpID to your old EmpID.

If your system has been in use for a while and other tables use your
current numbers, you have a problem that's not as easy to correct by
simply updating the number/key. Any help you get you should be willing
to pay for.

Juanica
http://www.youtube.com/watch?v=EAVJf5WMIEQ
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200806/1

Jun 27 '08 #3

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

Similar topics

6
by: Andrey | last post by:
What does the standard say about zero-initializing of static structures/classes, specifically: is it guaranteed by the standard that the alignment fillers between the members will also be...
6
by: Sulsa | last post by:
Does memory allocated by opperator new has gaps, or is it one big block of memory??
2
by: Ken | last post by:
I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access could not create the sequence number as soon as the value has...
3
by: Robert McGregor | last post by:
Hi there, I was wondering if anyone could help with this problem. I have a table with about 250,000 rows that relate to files that have been processed elsewhere in our business. Each file has...
5
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from...
14
by: pat270881 | last post by:
hello, I have to implement a sequence class, however the header file is predefined class sequence { public: // TYPEDEFS and MEMBER CONSTANTS
6
by: Defcon2030 | last post by:
<bHey, can someone help me with this? I've been working on it for a few days now, and my head's starting to spin... </b> // FILE:ex1_imp.cxx // // // // CLASS IMPLEMENTED: sequence (see ex1.h...
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
1
by: altaey | last post by:
Question Details: Write a program to find and print a Fibonacci sequence of numbers. The Fibonacci sequence is defined as follow: Fn = Fn-2 + Fn-1, n >= 0 F0 = 0, F1 = 1, F2 = 1 Your...
0
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...
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,...
1
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
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,...
1
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: 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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.