auto number with a difference

goju

Registered User.
Local time
Today, 13:00
Joined
Apr 7, 2005
Messages
77
i have a table with names in it.

i need a number system to be automatic for the following.

when i put in john smith i need my third text box to generate the number JS/1000

then when i choose fred spears i need FS/1001, and so on.

each new record will be a rolling number, however the names are one of 10

any ideas.

newbie.
 
The moment you "structure" your autonumber field it ceases to be an autonumber by Access standards. I'm not saying you can't do what you asked, but it is not an autonumber any more.

This is a common question that many people ask in various forms. Search this forum for "Autonumber" topics. Many threads will discuss approaches you can use.
 
this looks like what im after can it be simplified.

Autonumber doesn't work this way. In your example, you get QUOT0001, QUOT0002, ORD0003, etc. if it is in the same table.

You have to do something different if you want a compound prime key with independent numbering for each sub-set of the key.

Let's consider a table like this:

tblMyTable

fldMyPKAlpha, text, first field of compound prime key, value can be defined by lookup if you wish, field either is not individually indexed or is indexed with Duplicates Allowed.

fldMyPKNumer, long, second field of compound prime key, value is defined in a way I'll show you in a moment. Field either is not individually indexed or is indexed with Duplicates Allowed.

of course, plus other fields as needed. The prime key is the compound of fldMyPKAlpha and fldMyPKNumer, and THAT (because it is a prime key) is indexed with NoDuplicates

OK, the way you assign the number is

1. Find the value for the Alpha part.

2. Run a 1+Nz( DMax( "fldMyPKNumer", "tblMyTable", "fldMyPKAlpha = """ & fldMyPKAlpha & """"), 0)

(or something like this, you might have to play with the quotes.)

In essence, this says "Tell me the next unused number that is 1 higher than the highest used number in the table for this particular Alpha key, and if the DMax can't find anything, give me number 1"

Note that this is NOT an autonumber, so it will not have gaps if you start to store something but abort the process. Autonumbers can leave gaps after aborting a number allocation. If you delete the highest number after an operation goes bad, you will RE-USE the number. If you delete lower numbers, you will have gaps.
 
Yea but unless you design your database PERFECTLY, you can have problems.

Also, why not just use a query? Why do you need your PK to be like that?
 

Users who are viewing this thread

Back
Top Bottom