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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert numeric to text, zero fill leading spaces

How To

Convert numeric to text, zero fill leading spaces

by  randysmid  Posted    (Edited  )
Hi,
It is often necessary to convert numeric fields to text, but you need to have leading spaces replaced with leading zeros. This often happens when you get data from another system that stores the data in a numeric format. A good example of this are zip codes. Another database might be storing the zip code for Boston (MA) as 2124, but it really should be "02124". If this numeric value were converted to text, we would end up with "2124" (LEFT JUSTIFIED!!!!).

Here's how to resolve this problem:
1) Make a backup copy of your table.
2) In Table design view, go ahead and convert the format to text and set the appropriate length. Save the table.
3) In Query, create a new query with the table just modified. Click on Query and change it to "Update Query".
4) Double-click on the field to be zero-filled.
5) For "Update to", enter code similar to this:
Format([zipcode],"00000")
Note: your fieldname must appear in brackets
6) Click on the Run button (exclamation mark in the top center of the Access window) to update all the records in your table.

HTH, Randy Smith
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top