473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Creating a Unique Employee ID

Hi all,

I am trying to create a unique Employee ID, but I am having a few issues.

The ID must contain 7 characters in the following Format.

* Characters 1-3 = "LTS"
* Characters 4-5 = Starts at "AA", then when 6-7 reaches 99 changes to "AB" and so on.
* Characters 6-7 = Starts at "00" or "10" (Doesn't matter), and rolls through to "99" before reseting to it's start point, as well as change characters 4-5 to the next in the sequence.


We already use this method but on paper and a looking to move to an electronic system, hence the question.

Many thanks,
LSM1604
Oct 25 '11 #1
3 8896
patjones
931 Expert 512MB
This is an issue that comes up from time to time on the forum. You seem to recognize the need for uniqueness, and have a method for achieving that (presuming that you have few enough employees that this method won't exhaust ID's). So my question for you is: what is your question? Are you simply looking for a way to assign them?

Pat
Oct 25 '11 #2
Hey,

Thank you for taking the time to reply.

All employees are currently maintained in a paper based system hence, already having the unique ID format.

However, we are looking to move this forward and use an electronic system. It would be benefical for us to have an automated number generator in the format of the existing system to allow a smooth transition.

I require a method for achieving this. (Unique ID generation and implementation)

Many thanks,
LSM1604
Oct 25 '11 #3
NeoPa
32,556 Expert Mod 16PB
You would want a form that is used for entering such employees. A mistake often made is to generate the ID before the record is saved. You should avoid this as it allows for duplicate IDs to be generated and noted before the save fails (potentially losing other work). For this reason I suggest the code is contained within the Form_BeforeUpdate() event procedure. The Default Value of the control could be set to "TBA" to make it clear to the operator what's going on.

The code needs to handle finding the maximum value so far used; applying your logic for working out the next available value; importantly - checking that the record being saved is a new one; etc.

Assumptions:-
  1. The table name is [tblEmployee].
  2. The field name in the record for Employee ID is [EmployeeID].
  3. The control name for the Employee ID is [txtEmploeeID].
  4. Where you say :
    * Characters 6-7 = Starts at "00" or "10" (Doesn't matter),
    You really mean :
    * Characters 6-7 = Starts at "00" or "01" (Doesn't matter),
    I will follow the "00" option anyway.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     Dim intNo As Integer
  3.     Dim strID As String, strX As String
  4.  
  5.     With Me
  6.         If Not .NewRecord Then Exit Sub
  7.         strID = Nz(DMax("[EmployeeID]", "[tblEmployee]"), "")
  8.         If strID = "" Then
  9.             .txtEmployeeID = "LTSAA00"
  10.             Exit Sub
  11.         End If
  12.         intID = Int(Right(strID, 2)) + 1
  13.         If intID > 99 Then
  14.             intID = 0
  15.             strX = Mid(strID, 5, 1)
  16.             strX = IIf(strX = "Z", "A", Chr(Asc(strX) + 1))
  17.             Mid(strID, 5, 1) = strX
  18.             If strX = "A" Then Mid(strID, 4, 1) = Chr(Asc(Mid(strID, 4)) + 1)
  19.         End If
  20.         Mid(strID, 6, 2) = Format(intID, "00")
  21.         .txtEmployeeID = strID
  22.     End With
  23. End Sub
There is no warning in this code when the range is exceeded. That can be added, and probably should be, but it's not a part of this question.
Oct 25 '11 #4

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

Similar topics

3
by: Darrel | last post by:
I have a table that stores the content for a web site I'm making. Each one has a unique ID so I can grab it via the querystring. Since it's being done via a query string, I didn't want to use...
5
by: Greg Corradini | last post by:
Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned...
3
by: travis.downs | last post by:
Hi, I'm trying to use a macro to create a unique temporary variable name, such as #define TEMP_OBJ(string) MyType obj_ <some magic here(string); So something like TEMP_OBJ("foo")
11
by: breal | last post by:
I have three lists... for instance a = ; b = ; c = ; I want to take those and end up with all of the combinations they create like the following lists
4
by: mopiforu | last post by:
HI, I am creating a web server in which user will upload a file, in my cgi script using the upload method i am getting the file handle and writing the file in my hard drive, later am using the...
0
by: Rajesh Kumar Joshi | last post by:
I have a table with only 1 column as Table : profileTable //-------------- profile XML; //-------------- A sample content of XML file is <sampleprofile name="joe" version="A123">...
13
by: mliptak | last post by:
I'm trying to implement logging in my application, so that each log message has its unique identifier, e.g. log(identifier, text) What I want to achieve is that the compiler screams if the log()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...

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.