primary key

J

JB

Hello
Would it be possible to make the primary key of a table which is AutoNumber,
have or start with 3 digits?
Instead of 1 can I make it to show 001 then 002 and so on?
Thanks
 
K

Klatuu

That would be incorrect use of an autonumber field.
Autonumber fields should never be seen or used for any meaningful data.
Their sole purpose is for surrogate primary keys and as a value to assign to
child records as a foreign key. The value of any field, variable, or
control can be presented with leading zeros using the Format function.

Additionally, you cannot expect a continuous unbroken sequence of numbers
with an autonumber field. There will be gaps caused by a user beginning a
record, but canceling or undoing the record before it is actually written to
the table. The number is assigned as soon as the first character is typed
into the first control on a form and whether the record is saved or not, the
number is consumed and will not be reused.

Please explain what you are wanting to do and perhaps we can help with the
how to do it.
 
J

JB

Yes actually you've got a point.
I wanted the number to have more digits only because when I ran the report,
the OrderId number being 1 or 2 etc, seemed too insignificant. Having the
leading zeros just made it look better.
But reading what you said, I'm maybe being a tad too picky.
Thanks for the explanation though
J
 
K

Klatuu

If you need a sequential numbering system for an Order Number and you want it
to start with 3, here is a way to do that:

Me.txtOrderNumber = Nz(DMax("OrderNumber","tblOrderHeader"), 2) + 1

And when you want it to show 3 numbers long use the Format property of the
control where you display it as 000

Now, there are a couple of issues. If you have multiple users entering
orders, it is possible they can both get the same number if they haven't
saved the new order yet. But there are a number of techniques for doing that.
 

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