How can we have a field assign a num. automaticly starting with 29

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

My goal is as follows:

We use the 1st two numbers to specify the year our customer sign up & the
last four will be there account number. We would like the program to assign
the number so we don't use the same number twice.
 
Dan said:
My goal is as follows:

We use the 1st two numbers to specify the year our customer sign up & the
last four will be there account number. We would like the program to assign
the number so we don't use the same number twice.

It's usually a bad idea to "overload" the use of a field like this - why
not have a column for the date they sign up, and another for the account
number? Complexity really is your enemy, and your 1000th customer will
break the database long after anyone remembers how it was built! You
can assign the account number as an autonumber. Help (Access 2003) has
an item about changing the starting number. Otherwise, just set the
field property to allow no duplicates and add one to the highest number
already in the table. (think Select, max).

Phil
 
That would be in inappropriate use of an Autonumber.
I fully agree with the concept it should be two fields, but the use of
autonumber fields should be limited to artificial or surrogate keys and
should never be seen by a user.

Even if the above were not good practice, you cannot depend on autonumbers
to stay sequential. There will be gaps. Any time you start a new record,
but cancel the update, the number is discarded.

If you need truely sequential numbers with no gaps, the better practice
would be to use a DMax function to return the highest current number in the
table and add 1 to it. There are multiple techniques for doing this. The
main area you have to be aware of is handling this in a multi-user
situation.
 
Klatuu said:
That would be in inappropriate use of an Autonumber.
I fully agree with the concept it should be two fields, but the use of
autonumber fields should be limited to artificial or surrogate keys and
should never be seen by a user.

Even if the above were not good practice, you cannot depend on autonumbers
to stay sequential. There will be gaps. Any time you start a new record,
but cancel the update, the number is discarded.

If you need truely sequential numbers with no gaps, the better practice
would be to use a DMax function to return the highest current number in the
table and add 1 to it. There are multiple techniques for doing this. The
main area you have to be aware of is handling this in a multi-user
situation.


Interesting comments on Autonumbers, and indeed, the prevailing wisdom,
but I'm not convinced they have only one use. Klatuu is quite right to
point out that there can be gaps, but this needn't be a problem if it's
understood. These things look like numbers, but they don't support most
arithmetic operations beyond identity comparison and magnitude
comparison - a so-called "ordinal" scale. It doesn't make sense to
increment them, let alone add, subtract, multiply or divide them - just
like account "numbers". They provide an effortless unique identifier,
and are widely used for primary keys, but I don't see why they can't be
used for other purposes if their limitations (as well as their
strengths) are understood. Is there any reason why a table couldn't
have two autonumber fields? Why shouldn't they ever be seen? Happy to
be put straight on this - I'm no guru.

Phil
 
You can have multiple Autonumber fields is a table, but I can't, at the
moment, think of a useful purpose to do so.

You can do whatever you want with autonumber fields except change the value
of the field. You could use them in an arithmetic operation, but again, I
don't know of any examples I can offer.

Database normalization rules state that each field be an atomic piece of
information. There is no meaningful information in an Autonumber field. It
was designed specifically as an internal tool to easily create surrogate
keys without have to include logic in an application to generate them.

With that said, there is and will always be opinions and discussions on the
use of surrogate keys. I am in favor of them, but that is beyond the scope
here.

As to why hide them. When something is visible to users, they will want to
attach some meaning to it and try to use it. As Autonumbers values can't be
controled, change nor predicted, I prefer users not even know they exist.

This, of course, is not a technical discussion, this in my personal
philosophical opinion based on study of those I consider more enlightened
than I and my experience.
 
Pardon me, but as far as I know, you can only have ONE autonumber field in a
table. I just tried adding a second one in Access 2003 (JET db engine) and
got an error message saying I was only allowed one autonumber field in the table.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
Thanks, John. I was not aware of that.
As I did say, I can see no reason to have more than one, so I guess I have
never even tried.
Thanks for the correction.
 
Well, even if you could have more than one, they would probably be identical.

Like you I can not really envision any good reason for having two autonumbers
in one table.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
Well, even if you could have more than one, they would probably be
identical.

Doh!

Guess I should open the want ads and look under day laborers wanted <g>
 
John said:
Well, even if you could have more than one, they would probably be
identical.

Like you I can not really envision any good reason for having two
autonumbers in one table.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Not surprised you can't have more than one. The point I was making is
that an autonumber gives you a value which is guaranteed to be unique,
and that's pretty much all you need for an account number. Even if
there was some reason not to use the PK as an account number (I do use
it for Invoice Number in one application) then I was speculating whether
you could have a second Autonumber field to generate arbitrary Account
Numbers. If you look on your gas bill and study your account number -
what is it, if not a primary key?

Phil
 
Philip said:
Not surprised you can't have more than one. The point I was making is
that an autonumber gives you a value which is guaranteed to be unique,
and that's pretty much all you need for an account number. Even if
there was some reason not to use the PK as an account number (I do use
it for Invoice Number in one application) then I was speculating whether
you could have a second Autonumber field to generate arbitrary Account
Numbers. If you look on your gas bill and study your account number -
what is it, if not a primary key?

Phil

US readers note - what you call "gas" is properly called "petrol". The
"gas bill" referred to is for domestic heating supply!

Anyway, these differences should diminish now that you are to have an
Irish president. We all wish Senator O'Bama all the best.

Phil, London
 
The Irish were really puzzled about why we were even bothering to have an
election.

One the one hand we had a pant suit wearing lawyer married to a lawyer what
can't keep his pants on supporting a lawyer who is married to a lawyer who
doesn't even like the country her husband wants to be president of and on
the other a fellow with a name start starts with Mc married to a beautiful
rich lady who owns a brewery distributorship. So why, they wonder, is there
even a question.

You are confusing gas with gas.
The qas you put in your car is gasoline
The gas bill refers to natural gas used for heating.
domestic heating supply is too ambiguous. It could be gas, electricity,
oil, coal?
 
Klatuu said:
The Irish were really puzzled about why we were even bothering to have an
election.

One the one hand we had a pant suit wearing lawyer married to a lawyer what
can't keep his pants on supporting a lawyer who is married to a lawyer who
doesn't even like the country her husband wants to be president of and on
the other a fellow with a name start starts with Mc married to a beautiful
rich lady who owns a brewery distributorship. So why, they wonder, is there
even a question.

You are confusing gas with gas.
The qas you put in your car is gasoline
The gas bill refers to natural gas used for heating.
domestic heating supply is too ambiguous. It could be gas, electricity,
oil, coal?

I think we should let the ambassadors work this one out...
:-)
 
No, I think military action is required :)
We haven't had a good tussle with you guys since 1812.
Hey, but don't burn the White House again. That was really inconvenient.

Oh, wait. That was actually the Canadians :)
 
Klatuu said:
No, I think military action is required :)
We haven't had a good tussle with you guys since 1812.
Hey, but don't burn the White House again. That was really inconvenient.

Oh, wait. That was actually the Canadians :)

Glad you figured that one out.

Tony (Canadian)
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Back
Top