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  

auto increment



 
 
Thread Tools Display Modes
  #1  
Old May 6th, 2009, 08:04 PM posted to microsoft.public.access.tablesdbdesign
Dorian
external usenet poster
 
Posts: 542
Default auto increment

It's not good database design to have hidden data in a column e.g. the year
'hidden' in a primary key. Stick with the autonumber primary key and put the
year into another column.
Does the sequence number really have to restart at 1 for each new year?
No, you cannot do what you want in table design, you would have to create
the key manually yourself.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
  #2  
Old May 7th, 2009, 12:58 PM posted to microsoft.public.access.tablesdbdesign
Noëlla Gabriël
external usenet poster
 
Posts: 79
Default auto increment

Hi,

it's not because you need a unique field it has to be the primary key. The
same situation exists in invoice numbering, they have to be continuously
numbered and restart with 1 each year. The most used solustion for that is:
the pk field is, as usual, an autonumber which is hidden for the users. The
unique invoice number, or ticket number in this case, is build automatically
from the sysCounters table.
You can create this table with the following fields:
countID (autonumber) = PK field
countType (text or number if you have a related types table), in my case
this is a text field with the following 3 records: INV(invoice), CRN(credit
note), PRF(Pro Forma); in your case you need only TICKET
countYear (the year the counter is used, this makes it possible at the
beginning of a year to create a ticket for the last year, or to create
already a ticket for the next year at the end of a year)
countValue: the last used number.

all you have to do on creation of a new record is to use a dlookup function
to get the last number, build the correct ticket number with this number + 1,
and then update the counters table with this new last number.

Succes
--
Kind regards
Noëlla


"Dorian" wrote:

It's not good database design to have hidden data in a column e.g. the year
'hidden' in a primary key. Stick with the autonumber primary key and put the
year into another column.
Does the sequence number really have to restart at 1 for each new year?
No, you cannot do what you want in table design, you would have to create
the key manually yourself.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".

  #3  
Old May 7th, 2009, 07:56 PM posted to microsoft.public.access.tablesdbdesign
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default auto increment

Noëlla

I've used a variation on your approach, but done away with the separate
table.

I have a [SequenceNumber] field (the same as your countValue) in each record
in my "main" table, as well as a [RecordYear] field.

When it comes time to add a new record, I first require the user (via a
form, of course!) to indicate the applicable year, then use a simple
function to find the largest [SequenceNumber] already used where
[RecordYear] matches the indicated applicable year. Then I add 1.

I have to futz with it a bit to handle the 'first record of the year'
situation, but that's not complex either.

Regards

Jeff Boyce
Microsoft Office/Access MVP

"Noëlla Gabriël" wrote in message
...
Hi,

it's not because you need a unique field it has to be the primary key.
The
same situation exists in invoice numbering, they have to be continuously
numbered and restart with 1 each year. The most used solustion for that
is:
the pk field is, as usual, an autonumber which is hidden for the users.
The
unique invoice number, or ticket number in this case, is build
automatically
from the sysCounters table.
You can create this table with the following fields:
countID (autonumber) = PK field
countType (text or number if you have a related types table), in my case
this is a text field with the following 3 records: INV(invoice),
CRN(credit
note), PRF(Pro Forma); in your case you need only TICKET
countYear (the year the counter is used, this makes it possible at the
beginning of a year to create a ticket for the last year, or to create
already a ticket for the next year at the end of a year)
countValue: the last used number.

all you have to do on creation of a new record is to use a dlookup
function
to get the last number, build the correct ticket number with this number +
1,
and then update the counters table with this new last number.

Succes
--
Kind regards
Noëlla


"Dorian" wrote:

It's not good database design to have hidden data in a column e.g. the
year
'hidden' in a primary key. Stick with the autonumber primary key and put
the
year into another column.
Does the sequence number really have to restart at 1 for each new year?
No, you cannot do what you want in table design, you would have to create
the key manually yourself.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and
they
eat for a lifetime".



 




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 06:36 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.