MS Access Customizing an Auto Number

A

April Klein

Hi -

I would like to create my own auto number. It should include:

project acronym+date+####

Example: 65947WHB-CAE_042210-0001

I have a table set up that I can pull the project acronym from, the date
would be the date entered into the database, the number would generate
automatically. What is the best way to do this?

Thanks for your help.

April
 
J

John W. Vinson

On Thu, 22 Apr 2010 14:08:03 -0700, April Klein <April
Hi -

I would like to create my own auto number. It should include:

project acronym+date+####

Example: 65947WHB-CAE_042210-0001

I have a table set up that I can pull the project acronym from, the date
would be the date entered into the database, the number would generate
automatically. What is the best way to do this?

Thanks for your help.

April

This is a Very Bad Idea. It's called an "Intelligent Key" in the jargon, and
that's unfortunately not a compliment!

A field should be "atomic", containing one and only one indivisible piece of
information. A project acronym is one atomic piece of information; a date is a
different piece; a sequential number is yet a third. These should be stored in
three separate fields in your table; they can be concatenated together for
display purposes if you wish.

An Access Autonumber will not serve your turn - it's a meaningless unique
number, not even guaranteed to be sequential.

I'd suggest having three fields: a Text ProjectID field, a Date/Time DateAdded
field, and a Number... Long Integer SeqNo field in your table. Use a Form to
add data to the table. On the form you would put a combo box named
cboProjectID based on the table of project acronyms bound to the ProjectID;
set the Default Value of the DateAdded field to =Date(); and put the following
VBA code in the AfterUpdate event of the combo box:

Private Sub cboProjectID_AfterUpdate()
If Not IsNull(Me!cboProjectID) Then
Me!SeqNo = NZ(DMax("[SeqNo]", "[yourtablename]", _
"[ProjectID] = '" & Me!cboProjectID & "'")) + 1
End If
End Sub
 
T

Tony Toews [MVP]

April Klein said:
Example: 65947WHB-CAE_042210-0001

To add to John's comment does everyone in your organization or
everyone who will ever see this number use ddmmyy format? Personally
I find these dates confusing as I'm never quite sure what data format
this is Essentially in the first 12 days of the month.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
 
P

Paul Shapiro

Tony Toews said:
To add to John's comment does everyone in your organization or
everyone who will ever see this number use ddmmyy format? Personally
I find these dates confusing as I'm never quite sure what data format
this is Essentially in the first 12 days of the month.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/

Ever since Y2K, which was also around the time I wrote applications for
multi-national clients, I've used yyyymmdd as the date string format to
reduce possible confusion. If you can include periods or dashes, yyyy-mm-dd
for example, it becomes even clearer.
 
T

Tony Toews [MVP]

Paul Shapiro said:
Ever since Y2K, which was also around the time I wrote applications for
multi-national clients, I've used yyyymmdd as the date string format to
reduce possible confusion. If you can include periods or dashes, yyyy-mm-dd
for example, it becomes even clearer.

The ISO data format uses dashes so I go with that rather than using
periods.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top