cdl1701
Golom / Leslie / RoyVidar / PHV have presented one solution where you use the autonumber feature for numbering a record, and format the number to your requirements. Since you seem to want the number to display per your format requriements, then use a function...
Code:
Function [COLOR=blue]MyFormat([Job Number] as Long)[/color] as String
MyFormat = "T" & Format([JOB NUMBER], "00000")
End Function
For example, pretend the following field / column variables match the ones you use in your database...
SELECT MyFormat([Job Number]), JobDate, Contractor from JobTable
Since you have created
MyFormat as a public function, the function will format the number for you.
Then you can call the format from anywhere, including within a query. If you need to change the formatting, for example "T" -> "U", you make the change at one location.
Having said all this, if you want to store the number without formatting, meaning store the number as a text string, then you may wish to use an administrative table to store control numbers as per my aforementioned link.
Please note:
0000123 - has to be stored as a text string
123 - can be stored as a string or a number
Adding numbers is a heck of a lot easier than adding strings (which requires the extraction of the number, perform the math and convert the number back to a string).
Lastly, sometimes we like our numbers to be ordered / in sequence and we forget that we really just want the numbers to identify something - in your case a Job Number. Developers and programmers would consider having sequential numbers that are used solely for identification as "cosmetic", where the sequential numbering is not a really necessary.
The exception to this is when sequential numbers is used for control / audit purposes -- cheque numbers, invoice numbers. In this case, a missed number can be a cause for concern.
If your purpose is to use sequential numbers for control purposes, the use of auonumbers is not without issues. In a multi-user database, you can experience problems, and even with a single user database, may find that you loose the occasional number. There are numerous posts on AutoNumber issues. Here is a test, start to create a Job record. Notice that the autonumber will be displayed as soon as you start to enter the record. Now hit the escape key twice - the record clears. Now start to enter a new record -- the autonumber will have advanced to the next number -- you just lost a number. This is not a "big thing" if you are using numbers for identification. If the numbers are to be used for control, now you may have to document what happened. (Which is why for this type of activity, I use a control table)