Updating text "numbers" w/ leading zeros

G

Guest

I searched for a prior answer to this question but couldn't find exactly what
I needed, so here goes. We have a database in which ID "numbers" (actually a
text field) are used to identify clients. It is the primary key. The newer
client IDs are now up into five "digits", but the older ones are only four.
The department head now wants ALL client numbers to be five "digits" long,
which means a leading zero will have to be added to all the existing four
"digit" IDs. Is there an easy way in which this can be done?

This ID number is the linking field in a one-to-many relationship to a table
in which we list all the services that client has received (date and units of
service) through a subform. Can the same update process be used to add a
leading zero to the four digit ID numbers in the service table? There are
several thousand service entries, and to do it manually would be a chore!
Thanks in advance for any help.
 
R

Rick Brandt

Susan said:
I searched for a prior answer to this question but couldn't find
exactly what I needed, so here goes. We have a database in which ID
"numbers" (actually a text field) are used to identify clients. It
is the primary key. The newer client IDs are now up into five
"digits", but the older ones are only four. The department head now
wants ALL client numbers to be five "digits" long, which means a
leading zero will have to be added to all the existing four "digit"
IDs. Is there an easy way in which this can be done?

This ID number is the linking field in a one-to-many relationship to
a table in which we list all the services that client has received
(date and units of service) through a subform. Can the same update
process be used to add a leading zero to the four digit ID numbers in
the service table? There are several thousand service entries, and
to do it manually would be a chore! Thanks in advance for any help.

Use an Update query...

UPDATE TableName
SET [TableName]![ID] = Format(Val([TableName]![ID]), "00000")

(please test on a copy of your table)
 
G

Guest

First make sure the relations have Cascade Update Related Fields checked.

Use an update query like this SQL statement.
UPDATE NumberMain SET NumberMain.ID = Right("0000" & [ID],5);
 

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