A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

autonumber question



 
 
Thread Tools Display Modes
  #1  
Old October 7th, 2009, 09:45 PM posted to microsoft.public.access.tablesdbdesign
JOM
external usenet poster
 
Posts: 40
Default autonumber question

I want my auto number to be in the form of todays date and then the record
number e.g., 10070901. If I enter a new record tomorrow, I want it to start
with tomorrows date and start at 01. Is that possible?
  #2  
Old October 7th, 2009, 10:28 PM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default autonumber question

On Wed, 7 Oct 2009 13:45:01 -0700, JOM wrote:

I want my auto number to be in the form of todays date and then the record
number e.g., 10070901. If I enter a new record tomorrow, I want it to start
with tomorrows date and start at 01. Is that possible?


No, not with an Autonumber; an autonumber has one purpose only - to provide a
meaningless unique key.

And it's a Bad Idea anyway. A date *IS DATA* and should be stored in a date
field, as data, not embedded in the Primary Key of your table. A field should
be "atomic" - containing only one piece of information; and a primary key
should emphatically not depend on the value of any other field in the table.

If you want to just display this composite, you can use a date field to store
the entry date (just set its DefaultValue property to =Date() ), and a Number
field which you can increment in your form's BeforeInsert event:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!SeqNo = NZ(DMax("[SeqNo]", "yourtablename", "[Datefield] = Date()")) + 1
End Sub

and concatenate them for display purposes. I'd use an Autonumber as the
primary key, but - if you insist - you could make this date field and the
SeqNo field a joint two-field primary key.
--

John W. Vinson [MVP]
  #3  
Old October 7th, 2009, 11:59 PM posted to microsoft.public.access.tablesdbdesign
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default autonumber question

As it happens, I agree with John on this ... a unique record identifier does
only that - uniquely identifies a row.

But just so you know, some folks feel that there are unique "natural" keys,
pieces of data that are both unique AND provide data about the table's
topic.

As an example, if you had a way of ensuring that your table would NEVER have
more than one record added at the same exact instant in time, a date/time
field filled using the Now() command could provide a unique identifier.

Careful who you bring this up with, though, as the subject of "natural" vs.
"arbitrary" primary keys is a matter of religious preference for some...

Regards

Jeff Boyce
Microsoft Access MVP

"JOM" wrote in message
...
I want my auto number to be in the form of todays date and then the record
number e.g., 10070901. If I enter a new record tomorrow, I want it to
start
with tomorrows date and start at 01. Is that possible?



  #4  
Old October 8th, 2009, 01:47 AM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default autonumber question

On Wed, 7 Oct 2009 15:59:32 -0700, "Jeff Boyce" wrote:

Careful who you bring this up with, though, as the subject of "natural" vs.
"arbitrary" primary keys is a matter of religious preference for some...


HERETIC! BLASPHEMER! getting out the torches and pitchforks

g
--

John W. Vinson [MVP]
  #5  
Old October 8th, 2009, 04:24 PM posted to microsoft.public.access.tablesdbdesign
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default autonumber question

Coming from you, John, I take that as a fine compliment!

Regards

Jeff Boyce
Microsoft Access MVP

"John W. Vinson" wrote in message
...
On Wed, 7 Oct 2009 15:59:32 -0700, "Jeff Boyce"
wrote:

Careful who you bring this up with, though, as the subject of "natural"
vs.
"arbitrary" primary keys is a matter of religious preference for some...


HERETIC! BLASPHEMER! getting out the torches and pitchforks

g
--

John W. Vinson [MVP]



  #6  
Old October 9th, 2009, 07:16 AM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default autonumber question

On Thu, 8 Oct 2009 08:24:46 -0700, "Jeff Boyce" wrote:

Hey, I'm a heretic and a blasphemer too!
(i.e. that's how I intended it)

Coming from you, John, I take that as a fine compliment!

Regards

Jeff Boyce
Microsoft Access MVP

"John W. Vinson" wrote in message
.. .
On Wed, 7 Oct 2009 15:59:32 -0700, "Jeff Boyce"
wrote:

Careful who you bring this up with, though, as the subject of "natural"
vs.
"arbitrary" primary keys is a matter of religious preference for some...


HERETIC! BLASPHEMER! getting out the torches and pitchforks

g
--

John W. Vinson [MVP]


--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.