Question : Leading zeros

I have a column of numbers imported from a spreadsheet that are five, six or seven digits in length, and they need to be updated to all be eight digits in length by inserting leading zeros.

Two questions:

First, is there a simple update query that will do this?

Second, is there a simple function I can write that will do this when I import the spreadsheet?

Thanks!

Answer : Leading zeros

The zero's will disappear because Access will make the fielddefinition numeric when it finds numbers in the first eight rows :-(
Importing a table like this (with a "textnumber") I do with copying the header row with the fieldnames to row 2 of the sheet.
Now every column will be imported as text, but the cost is that the additional header row will have to be removed after the import...

For adding the leading zero's you have already two solutions, here a third:
UPDATE tblImport SET fieldtextnumber = right("00000000" & fieldtextnumber,8)

An alternative might be to link a table to the excelsheet (new table > link > chose .xls as filetype) and create a maketable query (or append query) to fill the final table directly in the proper way.
In that query you can also use the "add leading zero's code" from the above UPDATE statement.

Clear ? :-)

Nic;o)
Random Solutions  
 
programming4us programming4us