473,387 Members | 1,760 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,387 software developers and data experts.

Need to generate Unique Serial Numbers for each set of combination

satifali
ProjNo - 3 8 DIGIT CODE
DocType - 3 letters code
Typist - 3 letters code

There is a table for each of the above fields containing info enabling select appropriate ProjNo or DocType or Typist.

Master table has several other fields including document reference number filed which will be combination of [ProjNo]-[DocType]-[Tyist]-[Serial No]

We need to generate sequencial serial no for each Typist typing different type of document for a project & then store it to final result as shown above to a DocRefNo field in Master Table
Jan 19 '15 #1

✓ answered by jforbes

There are multiple ways of doing this depending on how often the Serial (Sequence) Numbers are being pulled, when you want them pulled (Form Open, New Record, Record/Form Save), whether or not you want them pulled from multiple places, and if you are using SQL Server or Access as your backend database.

As long as you are using Access as your backend, they are all pretty similar. Here is a function that with a little tweaking should do what you want:
Expand|Select|Wrap|Line Numbers
  1. Public Function getKey(ByRef sProjNo As String, ByRef sDocType As String, ByRef sTypist As String) As String
  2.      Dim sPrefix As String
  3.      Dim sLastKey As String
  4.      Dim iSequenceLength As String
  5.      iSequenceLength = 5
  6.      sPrefix = sProjNo & "-" & sDocType & "-" & sTypist
  7.      sLastKey = DMax("ReferenceFieldName", "MasterTableName", "MasterTableName LIKE '" & sPrefix & "*'")
  8.      getKey = sPrefix & Right("00000" & Val((Right(sLastKey, Len(sLastKey) - Len(sPrefix))) + 1), iSequenceLen)
  9.  End Function
If you as using SQL Server as your backend, you can put the code in a trigger. It would be similar to the above, but written in TSQL.

I used these as references for the above code:
http://bytes.com/topic/access/answer...mber-data-type
http://bytes.com/topic/access/answer...-access-2003-a

1 1083
jforbes
1,107 Expert 1GB
There are multiple ways of doing this depending on how often the Serial (Sequence) Numbers are being pulled, when you want them pulled (Form Open, New Record, Record/Form Save), whether or not you want them pulled from multiple places, and if you are using SQL Server or Access as your backend database.

As long as you are using Access as your backend, they are all pretty similar. Here is a function that with a little tweaking should do what you want:
Expand|Select|Wrap|Line Numbers
  1. Public Function getKey(ByRef sProjNo As String, ByRef sDocType As String, ByRef sTypist As String) As String
  2.      Dim sPrefix As String
  3.      Dim sLastKey As String
  4.      Dim iSequenceLength As String
  5.      iSequenceLength = 5
  6.      sPrefix = sProjNo & "-" & sDocType & "-" & sTypist
  7.      sLastKey = DMax("ReferenceFieldName", "MasterTableName", "MasterTableName LIKE '" & sPrefix & "*'")
  8.      getKey = sPrefix & Right("00000" & Val((Right(sLastKey, Len(sLastKey) - Len(sPrefix))) + 1), iSequenceLen)
  9.  End Function
If you as using SQL Server as your backend, you can put the code in a trigger. It would be similar to the above, but written in TSQL.

I used these as references for the above code:
http://bytes.com/topic/access/answer...mber-data-type
http://bytes.com/topic/access/answer...-access-2003-a
Jan 19 '15 #2

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

Similar topics

10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
1
by: Darren DeCoste | last post by:
I am trying to create an application in Access that I will be able to print bar code labels. A stumbling block that I have hit is the Serial Number on the bar code. I would like to be able to read...
3
by: Stewart Allen | last post by:
Hi there I'm trying to find part serial numbers between 2 numbers. The user selects a part number from a combo box and then enters a range of serial numbers into 2 text boxes and the resulting...
29
by: Lauren Wilson | last post by:
Does anyone know how the following info is extracted from the user's computer by a Front Page form? HTTP User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
1
by: Daniel Hilgarth | last post by:
Hello, I am currently trying to use XSLT for the creation of multiple HTML-files from a single XML-File. This HTML-files need to have links to each other. The following information might be...
3
by: ronnchpra | last post by:
Hello, I need help generating 50 unique numbers using rand() BETWEEN 1 and 100 and assign them to a array. I have worked out the number randomization and assignment, but I cant figure out how to...
12
by: Ivan Popov | last post by:
I need to generate a unique serial number for each field in the table. The serial number shall consist of two letters and six numbers, for example AA123456. Someone can suggest how to do it in MS...
13
by: Scott Kaempfe | last post by:
I need to identify parts we buy at our plant. I want to give each a unique serial number that is based on the date. We may have multiple parts on a given date so I want to have the unique serial...
10
by: Wishbone1 | last post by:
Using Access 2007, I need to create an automatic Serial Number. I am new to Access and with no knowledege of writing codes. Example "7235-4300" "7" will be the current year "235" is day...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
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...

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.