473,441 Members | 2,550 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,441 software developers and data experts.

How can i create a unique serial number in Access 2003?

i am using Access 2003 to create a form where i can fill out customer details and the jobs i carry out for them, i want my form to create a unique code in my "job number" field. i want the code to be the date then another number after that which increases by one every record e.g.

if i entered a record on september 12th 2012 i want the job number to be:

12091201

then the next record would be:

12091202


can anybody help me with this please?
Sep 12 '12 #1
2 5494
pod
298 100+
There is probably a better way to do this, but the following works:

You need to create three fields to do this

date_created : date the record is created
date_id : unique id for each date (duplicates are allowed for different dates)
unique_id : based on the two previous field

So before saving a record, you have to query your table for the last inserted [date_id] of the current day,
build your [unique_id] not forgetting to increment [date_id] by one,
then you could insert your new record with the following data:

[date_created]: 2012-09-12
[date_id] : (SELECT MAX (created_id) FROM tablename WHERE [date_created] = isToday ) + 1 = 73
unique_id : [yyyymmddii] = 2012091273
Sep 12 '12 #2
TheSmileyCoder
2,322 Expert Mod 2GB
pod is going in the right direction, so I will just expand a bit on what he has said.

I would create only 2 fields, one to store the date and one to store the ID of the record, and let the primary key be the combination of the two. If you truly need to display the combined ID I would then make a calculated field in the query or the form/report.

In your table, have fields Date_Created and lng_DailyID. In your form, bind these to textboxes txt_DateCreated and txt_DailyID. Ensure that both textboxes are locked (And possibly disabled).

Make the Default Value for the txt_DateCreated be "=Date()".

Select your FORM properties, go the event tab, and select the event Before_Update. In the dropdown, select [Event Procedure] and then click the ... on the right hand side.

Now this will take you the VBA window, and place the cursor inside a piece of text like so:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel as True)
  2.  
  3. End Sub
Modify the code to look like so:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel as True)
  2.   'Only apply to new records
  3.   If Me.NewRecord Then
  4.     me.txt_DailyID=nz(Dmax("lng_DailyID","[InsertTableNameHere]","DateCreated=#" & me.tb_DateCreated & "#"),0)+1
  5.   End If
  6. End Sub
The Dmax will find the max used ID for that day. In case its the first record of the day it will return null, which is why its encapsualted in a NZ(Dmax,0) which will safely convert the Null to 0, and finally it is incremented by one.



If you need to display your special ID, simply add to your query:
Expand|Select|Wrap|Line Numbers
  1. Serial: Format([DateCreated],"yymmdd") + lng_DailyID
Sep 12 '12 #3

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

Similar topics

1
by: Wayne Aprato | last post by:
I have a client who is running several Access 97 databases that I have written for them. They are about to upgrade to Access 2003. Is the default file format of Access 2003 still Access 2000 the...
1
by: Paul | last post by:
Hi Guys, I have written an application in Visual C#, I wish to add serial number validation dll to the installer, how do I go about doing this. Thanks in advance. Paul Mathebula
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...
5
by: Jassim Rahma | last post by:
my CPU mac address is BFEBFBFF000006F6 and my software name is : shefa is there any function or encryption way in C# to generate a 24 digits (alpha numeric) from both CPu MAC address and...
16
by: malteselemon | last post by:
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...
2
by: Lit | last post by:
Hi, How can I get the CPU serial number via C# How can I get a screen shot via C# Thank you, Lit
2
by: sheperson | last post by:
Hi, I have been working for several months on a sofware and now it is finished. I have a problem now and it is this: Because I live in a country which there is no copyright law in it (Iran!!!!)....
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...
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
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
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...
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.