473,387 Members | 1,771 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.

Create Invoice Number using year, month, day and a number that increments with one

Hi all,
I want to create an invoice number that looks like "YYMMDD01" which will increment with 1 for each invoice. But the next day, it will need to start at one again. Example:

Today: 13031600, 13031601,13031602
Tommorow: 13031700,13031701,13031702
Mar 16 '13 #1
5 6770
Seth Schrock
2,965 Expert 2GB
Might I suggest that you use a four digit year. Otherwise, the first invoice on January 1st 2013 will have the same invoice number as January 1st 2113. Or you could automatically delete invoices over 99 years old.

Have you tried anything?
Mar 16 '13 #2
I'll take that into consideration. Thanks.
I didn't try anything yet.
Mar 16 '13 #3
zmbd
5,501 Expert Mod 4TB
chrisbenett:
There are several examples within this site covering just exactly this topic.
My advice is as follows:
In your table - let's call it [tbl_invoice]
[tbl_invoice]![invoice_PK] autonumber and primary key
[tbl_invoice]![invoice_ProductionDate] date/time
[tbl_invoice]![invoice_seq] numeric long
(other fields for [tbl_invoice] as needed)
Now when you insert a record I would first pull the records for the date in question and then I would find the highest number in [tbl_invoice]![invoice_seq] for that date. You can do this using a few methods; however in this case I would use the domain function DMAX() (Domain Functions (v2007))with the criteria based on the date and returning the [tbl_invoice]![invoice_seq] value. If you have really huge data table I would set up the query to filter out the date first and then dmax() on that query; however, I have a table with several hundred (actually in the thousands) that using the basic dmax() on the table works fairly fast even with a split database over a LAN connection.

Now that you have that last [invoice_seq] value; create the next record and increment the sequence by one.

Now as for your invoice: to generate the lot number, in your query or the report, create a calculated field that combines the [tbl_invoice]![invoice_ProductionDate] formatted as you desire, and the [tbl_invoice]![invoice_seq]. The nice thing here is that if you have to change the invoice number format you only change the calculated field. Or say you need a custom invoice number for only one or two of your customers, then you can add conditionals and so forth.

You can do as Seth has suggested about the four digit year (and I second this) However, you need to consider what the life span of the numbering system is. For Tax records... I'd make sure that had a 20 year uniqueness at minimum. For something like we have in my lab the lot numbering system cycles thru based on the last number of the year... but anything that's already 10 years old has long since been discarded.

I have not provided code nor SQL at this point because it's always better to let the person asking the question try to solve the problem first; however, if you run into a specific issue, directly related to this thread, then please post back and we can take the next step.
Mar 16 '13 #4
Sorry for taking so long. I was caught up with other projects.
Are you suggesting to create a separate table or adding those fields to my existing table within access?
Apr 8 '13 #5
NeoPa
32,556 Expert Mod 16PB
The same table. I'm not sure having them in separate fields is necessary myself, but it certainly could work that way.

I tend to use DMax() with a Criteria that matches the date part of the value and an Expr that returns the numeric part. The returned value should be converted from a string using something like Val() and a lack of any entries found should be handled by using Nz(..., 0).

NB. No-one is likely to throw any code your way until you've shown preparedness to make the effort on your own behalf first.
Apr 9 '13 #6

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

Similar topics

5
by: Ken Fine | last post by:
I want my application to maintain a directory tree based on months and years, e.g.: 2004 January file file file February file
4
by: Negroup | last post by:
Hi, all. I would like to know if it is possible to create a datetime instance using a tuple instead of single values. I mean: >>> from datetime import datetime >>> t = (1, 2, 3) >>> dt =...
4
by: Tim | last post by:
Hello Everyone I'm sure that there is a simple answer to this but I was wondering if there was an elegant way to change the definition of the functions like year, month and day such that they...
2
by: Papegoja | last post by:
Hi, A week ago I had a question how to get MS Query to return a standard date to a "YEAR-MONTH" (YYYY-MM) format. I received a great answer from Jerry Boone!!! It follows: SELECT...
1
by: Frank Bishop | last post by:
I have been spoiled by some report writing tools that have intrinsic functions like Last Year Month-to-date. I'm looking for a way to emulate this in SQL Server now with my fields that are...
6
by: Jim Stools | last post by:
Any idea how to find the year, month and day from (Int32) 38896? 38896 presents 6/28/2006 in excel. The dates in the database are (all) stored as Int32's corresponding to the way dates are handled...
2
by: DaBrain | last post by:
I am trying to make a query on one table, an invoices table, and I want to see how many orders are in each month Year Month Count --------------------------- 2006 01 80 2006 ...
2
by: CindySue | last post by:
Hello--I've got a query that uses DatePart("m",) to select records for a particular month, and then a report based on that query. I'd like to be able to create a field in the report that says what...
5
by: girl23 | last post by:
I am using a function prototype to convert month number to month name. basically you ask the compiler to enter int from 1 to 12 and then convert it. printMonth ( number ); is the prototype and...
12
by: Be Borth | last post by:
I saw previous solutions to convert a month number (1) to a month name (January). I have a database with 200+ dates. In a query, I use the "Part" function DatePart("m",), to extract the month...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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
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,...

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.