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

How to use Autonumber & dates to create unique ID

I need to create a custom field that uses the month and year (0810) in combination with an auto number system which resets each month. So each time a record is created within a month the numbers will reflect this: 01-810, 02-810, 03-810; 01-0910, 02-0910 etc.

I saw a post that addressed this with programming language but I'm new at this and wonder if there's another way of doing it?

Thanks!!
Aug 3 '10 #1
7 11667
Hi Miranda,

Create a text box, highlight it and in properties in Data tab in Control Source type:

Expand|Select|Wrap|Line Numbers
  1. =Format(Date(),"mmyy") & Format([ID],"000")
Where "000" is a number of digits used for unique ID added after the date, so if you need a bigger number just use more 0's
Aug 4 '10 #2
Steven Kogan
107 Expert 100+
You'll need to use some sort of programming to do this.

If you are not comfortable with programming in VBA you may want to consider using a standard autonumber field that does not reset every month, and storing the date of the record in a separate date field. Then you can create reasonably simple queries to answer questions such as how many records were created in a particular month as well as how many records were created in the current month. Even if you are comfortable with programming, I would still consider this as a good alternative.

Otherwise, can you provide a link to the solution you already found? It may be a good starting point.

The solution would involve vba code that uses SQL to find the maximum number for the current month and add one to it. If there is none, then 1 would be assigned. The formatting of the key field would be as Anton described. The code would probably be placed in the before update event of a form.

If it is a multi-user database you'd have to handle the possibility that two users can generate the same ID if they are creating a record at the same time.

You should consider creating a key that can be easily sorted. For example, using the format yymm-#### would produce a key that sorts properly.
Aug 4 '10 #3
NeoPa
32,556 Expert Mod 16PB
Miranda, your posted data is inconsistent. I'll assume for now that the August items, like the September ones, will contain four digits rather than three. It is critical (much easier) for the data to be consistent if you want to sequence your data within each month.

You don't specify, but I'm guessing you want this value to be created for you on a form for when entering a new record?

PS. Actually Steven's post handles pretty well everything well. Key layout would be much better as he suggests. I would consider using the Form_BeforeInsert event though. It is actually not quite correct to show the value before it is created for two reasons :
  1. Logically, the value has not yet been assigned. It is only a best-guess at this stage, and makes little sense to show this to the operator.
  2. It is also possible that the record addition will be cancelled or delayed. Until the record is saved there is a very real potential for the same value to be assigned to another record (which would not be good).
If it is important for the operator to make a note of the value assigned then a MsgBox() with the information could be displayed within the Form_AfterInsert event procedure, always assuming that's even necessary. Newly added records are often (not always) visible on the same form.
Aug 4 '10 #4
Anton - I tried to enter the code but obviously didn't do it right. It gives me an error.

NeoPa - I do want the value to be created on a form when entering a new record. What I'm confused about (apologies for being slow) is where to enter the proper code and at what point in the code should Form_BeforeInsert go?
Aug 5 '10 #5
NeoPa
32,556 Expert Mod 16PB
Miranda Truehill: NeoPa - I do want the value to be created on a form when entering a new record. What I'm confused about (apologies for being slow) is where to enter the proper code and at what point in the code should Form_BeforeInsert go?
Technically, it doesn't matter where in the code the new procedure goes. If you go into Design View of the form you will see, in the Properties pane, a Before Insert property. Go there and select [Event procedure] from the drop-down and click on the elipsis button (...). This will open the code window with the stub of the procedure prepared for you.

It should be easy from there. Shout if you have any trouble :)
Aug 5 '10 #6
So I decided to split the fields. The second has the date in the format I need. The first will have the auto-numbering which will start from 0 at the beginning of every month. Can someone give me the exact code for that so I can just paste into the field?

Thanks guys!!!!
Aug 5 '10 #7
NeoPa
32,556 Expert Mod 16PB
We can't really write copy/paste code without any meta-data Miranda. If you can describe what your fields are named and what the controls on the form are named then we can see what we can do for you.
Aug 5 '10 #8

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

Similar topics

3
by: CJA | last post by:
Hi I have a script that will compact an Access MDB and a copy to a new folder. I would it to give each export a unique file name. I can do this with an absolute file reference but I am...
1
by: Antonio Lopez Arredondo | last post by:
hi ! system.io.path.gettempfilename() returns a unique file name in the TEMP folder. does anybody know how to create a unique file name in another folder ? thanks in advance, ant.
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
2
by: Jon | last post by:
I have an asp.net app that I've localized using satellite assemblies. It works wonderfully, even for displaying dates. My problem comes when I try to use one of those dates in a SQL query. I...
1
by: Martin Ho | last post by:
Two questions: 1.) I am copying a whole bunch of files from one directory, but I need to do a if command to copy on those which date of creation is the same as today's date. How do I do this...
1
by: scholzr | last post by:
I am trying to create a unique index value when uploading records to my table. In the past, I have used the autoincrement option in my MySQL database, but for this table I want to create the index...
4
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
1
by: sanju4kk | last post by:
I am attempting to create a module that I can call to create a new field in my temp table that will be an autonumber, and then assigned that new field as the primary key. I have been search high and...
9
jinalpatel
by: jinalpatel | last post by:
I want to create a primary key that is combined with several fields Autonumber+InspectorNo(1 to 5)+CountyNo(1 to 35)+Date How to create it ? Where to write code for it? Please help!!
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: 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
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
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
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,...

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.