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

VBA Access Delete Number 0 on import 1

Status
Not open for further replies.

Mrogersy

Programmer
Jun 17, 2005
7
US
I am trying to import a file into a table that has the field set as a text field. It is importing the number 00026422 as this, and I need to remove any preceeding 0's before import to read 264222.
Anybody know how to do this?
 


Hi,

Leading ZEROS are significant for TEXT fields, while they are meaningless for NUMEIC fields.

If it is a TEXT field, then you must replace the leading zeros with SOMETHING. What would that SOMETHING be? SPACES? Otherwize, you might have a situation like this
[tt]
00000003
00026422
[/tt]
result in
[tt]
3
26422
[/tt]
which will colate as
[tt]
26422
3
[/tt]
Unless you don't really care.


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I do not care, and would not like anything there (not even spaces). AFter I import the file, I am matching that number to another table which shows the number as 264522, instead of 264522, as it is being imported. My vendor sends the data two different ways, 264522 and 000264522.
Thanks,
Mike
 
Skip has a point but the exporting source may just 0 fill numbers left. If that is your case...

If you are importing into Access which your subject implies and it really is a numeric field, change the datatype in your table to a number of an appropriate type.

Otherwise you can convert it to a number using a function and update to this value after import.

Cint, cdbl, clong and Val are all functions that you may consider using to convert to a number.

 

My vendor sends the data two different ways, 264522 and 000264522.

Keep the leading ZEROS.

Use the Format function to PAD with ZEROS when they are missing, as the ID is ACTUALLY a 9 byte STRING.
Code:
Format(YourRef,"000000000")



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I would ask the vendor if it is a numeric field. If it is, fine they zero fill left on some exports and then you can get rid of the zero's. If it is a text field, I would insist that they include the zero's on both transmission of data.
 



In many instances, IDENTIFIERS contain all numeric characters, but they are NOT really NUMBERS with which you would ever do arithmetic.

Part Numbers, Invoice Numbers, Phone Numbers, SSNs, US 5-Digit ZIP Codes, are ALL examples of IDENTIFIERS that of do contain ONLY numeric characters.

The tip-offs:
[tt]
Leading ZEROS are significant
Length of the value is constant
Not used for math
[/tt]


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top