473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

leading zeroes in alphanumeric id number

Hi,

I have a text field as a unique id number for my database. It is in the format
CP????? where the first record will be CP00001, CP00002 etc. Unfortunately I cannot get my table or form to include the leading zeros so any help would be appreciated. I am not a programmer just a biologist trying to build a robust database for my work.

cheers

Andy
Mar 18 '08 #1
2 4956
Stewart Ross
2,545 Expert Mod 2GB
Hi. A text field is not the right one to use if you wish to have leading zeros displayed automatically. Does the CP prefix refer to another object? Is it always the same value or will it change according to other aspects of the data? If the answer to either of these is yes then you have a compound key - a multi-component key - which should be stored in two fields, not one.

The numeric component should be a number (a long integer or an autonumber field). The format property of a number field can be set to 00000 to ensure that values are displayed with 5 digits, any unused ones appearing as leading zeros.

Although autonumber fields have their drawbacks they do return unique values in ascending sequence. If you don't require a compound key you could keep the key field as a simple autonumber and use a query on your table to display its value with the prefix. in the query editor you could add the following calculated field:
Expand|Select|Wrap|Line Numbers
  1. Prefixed ID: "CP" & Format([ID field name], "00000")
-Stewart
Mar 18 '08 #2
missinglinq
3,532 Expert 2GB
Someone, John Vinson I think, once said "Autonumbers are not fit for human consumption!" and truer words have never been spoken! There are simply too many things that can cause gaps in Autonumbers, other than deleted records! And things such as corruption can cause procedures to be used that will change the autonumbers.

For ID numbers, especially where they will be referred to/referenced in hard copy documents (yes, people, some people do actually have non-PC generated documents) you really should use code to generate auto-incrementing numbers. It's not that difficult:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  If Me.NewRecord Then
  3.   If RecordsetClone.RecordCount = 0 Then
  4.    Me.IDField = "CP0001"
  5.   Else
  6.    Me.IDField = "CP" & Format(DMax("val(Right([MyID],5))", "YourTable") + 1, "00000")
  7.    End If
  8.  End If
  9.  End Sub
Where:

IDField is the textbox on your form holding the "number."
MyID is the field on your table holding the "number."
MyID is of Datatype Text.
YourTable is the name of your underlying table.

Welcome to TheScripts!

Linq ;0)>
Mar 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jean-michel | last post by:
I need to convert a decimal field to char() but also trim the leading zeroes. Any idea? I could not find any function to do that.
1
by: Mike P | last post by:
I'm trying to write the contents of a csv file to a table, but I am having problems with fields with leading zeroes. Whenever I save as csv I lose the leading zeroes. Does anybody know how to...
2
by: tomlebold | last post by:
How do you remove leading zeroes in a column? Update 0000123456 to 123456
8
by: stainless | last post by:
Is it possible, using the ToString function, to take an integer and conver to a string of fiexd width with the leading spaces padded with zeroes. e.g. integer 123 converted to a string of length...
9
by: jbaranski | last post by:
Access 2003 on XP pro machine... i'm running a crosstab query and an export to a 3rd party company showing different benefit plans for employees; specifically dental, vision and medical pulling...
9
by: marcelo27 | last post by:
I need to add leading zeroes to an input box. For example, the user enters "2" , I need to convert to a three digit number eg."002". If the user enters "23", I need to convert to "023" If the user...
4
by: lenygold via DBMonster.com | last post by:
I have the following column: 1.4.1 1.10.1 1.10.1.2.2 1.22.99.1 2 2.8.11 2.7.7
2
by: DanCole42 | last post by:
Newbie question, here. I have a database that frequently imports ZIP code data that frequently needs cleaning: 12365 6487 64684-3543 3213-6546
2
by: Smokey Grindel | last post by:
I basically need to remove any leading zeros and hyphens from a string... regex seemed like the best rout and using a replace regex method... anyone know of any good strings for this? The one I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.