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

Create Specific Unique Serial Number

Using Access 2003, I need to create an automatic Serial Number.
Example "7235-E001"

"7" is current year
"235" is day
"-E" is static
"001" is sequencial, restarting at "001" each day

I set a table field with "=right(Format(Now(),"yy") & Format(Format(Now(),"y"),"000"),4)" to create the year/day number.----I should be able to add &"-E"& to add the static "-E"----I tried to add this all together with the "autonumber", but that obviously failed since the autonumber will not reset each day. Also, I lost the placeholders on the sequencial number "001".

I have little to no knowledge of VB, and if possilbe, would like to keep all expressions regulated to queries and tables and forms. If not possible, I will see what I can understand.

Please keep in mind, I am a complete noob, so speak to me like I am an idiot. Thank you.
Aug 24 '07 #1
16 18181
ADezii
8,834 Expert 8TB
Using Access 2003, I need to create an automatic Serial Number.
Example "7235-E001"

"7" is current year
"235" is day
"-E" is static
"001" is sequencial, restarting at "001" each day

I set a table field with "=right(Format(Now(),"yy") & Format(Format(Now(),"y"),"000"),4)" to create the year/day number.----I should be able to add &"-E"& to add the static "-E"----I tried to add this all together with the "autonumber", but that obviously failed since the autonumber will not reset each day. Also, I lost the placeholders on the sequencial number "001".

I have little to no knowledge of VB, and if possilbe, would like to keep all expressions regulated to queries and tables and forms. If not possible, I will see what I can understand.

Please keep in mind, I am a complete noob, so speak to me like I am an idiot. Thank you.
I could only spend a very short time on this, but this Function should properly generate the next Serial Number per your specifications. There are only a couple of simple assumptions:
  1. Your Table Name is tblTest, make the appropriate substitution if necessary.
  2. The [SerialNo] Field within this Table is called [SerialNo].
  3. The Day component you refer to in the Serial Number is a Julian Date (number of Days from the first of the year).
  4. Any questions, feel free to ask.
    Expand|Select|Wrap|Line Numbers
    1. Public Function fGenerateNextSerialNumber()
    2. Dim strCurrentYear As String
    3. Dim strCurrentDay As String
    4. Dim strStaticValue As String
    5. Dim strSequentialNo As String
    6. Dim strLastSerialNo As String
    7. Dim strLastSequentialNo As String
    8. Dim strNextSequentialNo As String
    9.  
    10. strCurrentYear = Right(Year(Now()), 1)
    11. strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), Now()) + 1
    12. strStaticValue = "-E"
    13.  
    14. 'get ready to extract the Sequential Number
    15. strLastSerialNo = DLast("[SerialNo]", "tblTest")        'produces 7235-E001
    16. strLastSequentialNo = Right(strLastSerialNo, 3)         'produces 001
    17.  
    18. 'Generate the Next Sequential Number
    19. strNextSequentialNo = Format(Val(strLastSequentialNo) + 1, "000")   'produces "002"
    20.  
    21.   'Generate the next, Unique, Serial #
    22.   fGenerateNextSerialNumber = strCurrentYear & strCurrentDay & strStaticValue & strNextSequentialNo
    23. End Function
Aug 25 '07 #2
This is kind of what I was afraid of. I have no idea where I would put the VB in the database.
Aug 25 '07 #3
ADezii
8,834 Expert 8TB
This is kind of what I was afraid of. I have no idea where I would put the VB in the database.
Place =fGenerateNextSerialNumber() in the Default Value Property of the [Serial Number] Field. Anytime you add a New Record, the results of this Function will be placed in this Field.
Aug 25 '07 #4
Roger, I will have access to the database tomorrow morning, I will try at that time, thank you. I'll reply back whether I manage or not.
Aug 26 '07 #5
ADezii
8,834 Expert 8TB
Roger, I will have access to the database tomorrow morning, I will try at that time, thank you. I'll reply back whether I manage or not.
Just make sure to substitute your Table name for tblTest and your Field Name for SerialNo or else the code will not work.
Aug 26 '07 #6
To see if I could get this to work, I created a new table. I named the
table "tblTest. I entered 3 fields. Field 1 - ID (autonumber), Field 2
-
SerialNo (no format), Field 3 - data (no format).

I then went to the VB (Tools/Macro/Visual Basic Editor). I entered the
code as typed. When I opened the VB, it had autopopulated "option
compare database" on the top line, so I left that information in, and
placed the new code below it.

When I added =fGenerateNextSerialNumber into the default data for the
"SerialNo" field, the =fGenerateNextSerialNumber changed to read
="fGenerateNextSerialNumber".

I then changed the table to "datasheet view" and added data to the
"data" field, but the "SerialNo" field populated with
"fGenerateNextSerialNumber".

I went back to VB and deleted "option compare database", but the
"SerialNo" field still populates with "fGenerateNextSerialNumber" when
I add data to the "data" field.

Am I putting the code in the right place, or should I have formated the
"SerialNo" field somehow?
Hopefully I explained well enough.


Thank you.
Attached Images
File Type: gif t1.gif (18.7 KB, 992 views)
File Type: gif t2.gif (17.3 KB, 739 views)
File Type: gif t3.gif (18.8 KB, 743 views)
Aug 27 '07 #7
ADezii
8,834 Expert 8TB
  1. In Form Design View.
  2. Right Click on the [SerialNo] Field.
  3. Select Properties.
  4. Select the Data Tab.
  5. In Default Value, enter =fGenerateNextSerialNumber()
Aug 27 '07 #8
My apologies for not getting back to you in a timely manner, things have been hectic. I made the corrections that you pointed out. Now the database is giving me an error on the

strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), , Now()) + 1

line. When opening the serial number table, I receive "Compile error: Arguement not optional: warning, and it highlights the above mentioned script line.
Sep 7 '07 #9
ADezii
8,834 Expert 8TB
My apologies for not getting back to you in a timely manner, things have been hectic. I made the corrections that you pointed out. Now the database is giving me an error on the

strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), , Now()) + 1

line. When opening the serial number table, I receive "Compile error: Arguement not optional: warning, and it highlights the above mentioned script line.
It seems as though you inadvertantly added another comma, thus the Error. The correct syntax is:
Expand|Select|Wrap|Line Numbers
  1. strCurrentDay = DateDiff("d", CDate("1/1/" & Year(Now())), Now()) + 1
Sep 7 '07 #10
Roger, I will fix the error when I get backto the office on Monday. Thank you.
Sep 8 '07 #11
ADezii
8,834 Expert 8TB
Roger, I will fix the error when I get backto the office on Monday. Thank you.
You are quite welcome.
Sep 8 '07 #12
Sorry about taking so long to respond.

Thank you for your assistance, and the scripting!
Sep 27 '07 #13
HAMIZ
2
Dear ADezii,
When I enter =fGenerateNextSerialNumber(), in default value field property of tblTest.SerialNo and save, I receive notification stating "unknown function '=fGenerateNextSerialNumber()'". Further more I have added the code in class module of VB window. Can you please help on this issue?
Jun 2 '10 #14
ADezii
8,834 Expert 8TB
@HAMIZ
Make sure that the Function in in a Standard Code Module and not a Form's Module.
Jun 2 '10 #15
HAMIZ
2
Yes, It is in Standard Code Module.
it works fine in "LOCALS" VB window and gives correct result.

Along with my last statement, It also gives error for strLastSerialNo stating "Run Time error '94' Invalid use of NULL" if there is no any record in the said table, i.e. we have write 1st value in [SerialNo] manually.
Jun 2 '10 #16
Hello,

I would like to generate a unique Serial number for each record set.

The Format is:
Year-String-Counter ----- Format = YYYY-PPAP-0000

Where the table Name = tbl_Detail_PPAP
the field = SequenceNumber

This is my code:

Public Function fGenerateNextSerialNumber()

Dim SequenceNumber As String
Dim strCurrentYear As String
Dim strStaticValue As String
Dim strSequentialNo As String
Dim strLastSerialNo As String
Dim strLastSequentialNo As String
Dim strNextSequentialNo As String



strCurrentYear = Right(Year(Now()), 4)
strStaticValue = "-PPAP"

'get ready to extract the Sequential Number

'If SequenceNumber = 0 Then

strLastSerialNo = DLast("[SequenceNumber]", "tbl_Detail_PPAP") 'produces 2016-PPAP-0001

strLastSequentialNo = Right(strLastSerialNo, 4) 'produces 0001

'Generate the Next Sequential Number
strNextSequentialNo = Format(Val(strLastSequentialNo) + 1, "0000") 'produces "0002"

'Generate the next, Unique, Serial #

fGenerateNextSerialNumber = strCurrentYear & strStaticValue & strNextSequentialNo

DoCmd.RunCommand acCmdSaveRecord

'End If

End Function

I have followed the exact procedures as suggested above. The code is in the Standard module. When I run the code, I get the following error "Invalid use of Null (Error 94)" on the code line: strLastSerialNo = DLast("[SequenceNumber]", "tbl_Detail_PPAP")

Please help me..
Aug 9 '16 #17

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

Similar topics

7
by: Tony Clarke | last post by:
Hi, I'm trying to write a system thats used for about 50 clients that uses html forms and php to log details. The problem is that when a client loads the form page it's given a value which is...
8
by: Nitin | last post by:
Hello, We are trying to figure out how to get a unique identifier for a machine. Our application is a C# windows application that talks to our server via a webservice. Every time our webservice...
5
by: UJ | last post by:
Is there any number I can get that is truly unique for a computer that can't be changed? I want to have a system whereby I have a computer that accesses a web service based on some unique value...
9
by: expect | last post by:
Hello, Trying to get this MySql create table command to work, no luck. create sequence serial; CREATE TABLE outbound ( source char(100) default '', destination char(100) default '', sport...
4
by: Yavuz Bogazci | last post by:
Hi, we are developing an winforms application for task management. We want generate a serial number wich includes Username, Company Name and another Information as String. How can i create from...
0
by: BRINER Cedric | last post by:
Synopsis CREATE { TEMPORARY | TEMP } ] TABLE /table_name/ ( { /column_name/ /data_type/ ] | /table_constraint/ } ) ) ] ... ...
18
by: JJ | last post by:
Now I know this question has been asked many times, but I cannot seem to find a good site which summarises the methods possible in vb .net. I am after a way of producing a unique serial number...
6
by: Arne Beruldsen | last post by:
I have a windows app using vb.net 2005. I would like to create a serial number based on a couple of characteristics of the customers computer (computer name, HD number..etc). I don't need...
6
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk...
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
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
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...
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
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...

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.