PC Review


Reply
Thread Tools Rate Thread

autonumber question

 
 
JOM
Guest
Posts: n/a
 
      7th Oct 2009
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?
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      7th Oct 2009
On Wed, 7 Oct 2009 13:45:01 -0700, JOM <(E-Mail Removed)> 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]
 
Reply With Quote
 
Jeff Boyce
Guest
Posts: n/a
 
      7th Oct 2009
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" <(E-Mail Removed)> wrote in message
news:319BB2B0-3763-4773-9F5D-(E-Mail Removed)...
>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?



 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      8th Oct 2009
On Wed, 7 Oct 2009 15:59:32 -0700, "Jeff Boyce" <(E-Mail Removed)> 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]
 
Reply With Quote
 
Jeff Boyce
Guest
Posts: n/a
 
      8th Oct 2009
Coming from you, John, I take that as a fine compliment!

Regards

Jeff Boyce
Microsoft Access MVP

"John W. Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:(E-Mail Removed)...
> On Wed, 7 Oct 2009 15:59:32 -0700, "Jeff Boyce" <(E-Mail Removed)>
> 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]



 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      9th Oct 2009
On Thu, 8 Oct 2009 08:24:46 -0700, "Jeff Boyce" <(E-Mail Removed)> 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" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
>news:(E-Mail Removed)...
>> On Wed, 7 Oct 2009 15:59:32 -0700, "Jeff Boyce" <(E-Mail Removed)>
>> 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]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autonumber question OD Microsoft Access VBA Modules 1 1st Sep 2009 06:31 PM
PK - To AutoNumber or Not To AutoNumber - That is the Question! :- =?Utf-8?B?ZGVl?= Microsoft Access Database Table Design 40 9th Aug 2007 08:52 AM
AutoNumber question =?Utf-8?B?RXJpYyBAIENNTiwgRXZhbnN2aWxsZQ==?= Microsoft Access 3 27th Dec 2005 08:24 PM
Autonumber question Joe Williams Microsoft Access Form Coding 2 12th Jan 2004 07:30 PM
Autonumber Question Joe Williams Microsoft Access Form Coding 1 31st Dec 2003 09:29 PM


Features
 

Advertising
 

Newsgroups
 


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