Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

field length

Status
Not open for further replies.
Aug 24, 2005
56
US
I got an ID field (text field) containing IDs with varying lengths. Some are 4 characters (9455) and some go all the way up to 9 characters (900034233). Is there any way to convert all IDs to a 10 character format by having the required X amount of zeros precede each ID?

Thanks,

Kevin
 
The format function only works in displaying values, it doesn't change the data in the table.

I think you might have use code to update those values since they are of varying lengths.

Create a recordset with just that one field in it and loop through the records. Within that loop try something like this:

incr = 0
counter = 10 - len(rst.IDfield)
prefix = ''

while incr < counter
prefix = prefix & '0'
loop

rst.IDfield = prefix & rst.IDfield
rst.Update

I would have to check the exact syntax but hopefully you get the idea. It seems a little clumsy to me but this idea should work.
 
If you want to change the values in the table (as opposed to just displaying them with leading zeros), run an update statement
Code:
UPDATE myTable 

SET ID = Right("0000000000" & ID, 10)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top