Need help formatting data for export, filling in zeros

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to add zeros to the leading part of a number that I'm exporting. The
numbers are being exported as text and have three or four digits. i.e. "845"
or "1435" I need to have them export as "00000845" or "00001435". Seems
like it should be easy but I'm going in circles. Any suggestions would be
greatly appreciated.

P.S. I am a geek (Network Engineer) but not a programmer so be gentle.
 
I need to add zeros to the leading part of a number that I'm exporting. The
numbers are being exported as text and have three or four digits. i.e. "845"
or "1435" I need to have them export as "00000845" or "00001435". Seems
like it should be easy but I'm going in circles. Any suggestions would be
greatly appreciated.

P.S. I am a geek (Network Engineer) but not a programmer so be gentle.

This function's input parameters are an integer and its desired zero-
filled format length. It prepends a zero-filled string to the string
value of the number. It returns the rightmost nLength characters.
Try using this logic:

Private Function ZeroFillInteger(nWholeNumber As Integer, nLength As
Integer) As String

Dim str0000 As String

Dim sZeroFilled As String

str0000 = "00000000000000000000000000000000000"

sZeroFilled = Right$(str0000 + CStr(nWholeNumber), nLength)

ZeroFillInteger = sZeroFilled

End Function

Lou Phillips
 
Jeff said:
I need to add zeros to the leading part of a number that I'm
exporting. The numbers are being exported as text and have three or
four digits. i.e. "845" or "1435" I need to have them export as
"00000845" or "00001435". Seems like it should be easy but I'm going
in circles. Any suggestions would be greatly appreciated.

P.S. I am a geek (Network Engineer) but not a programmer so be gentle.

What are you exporting them to? Numbers by nature do not have leading
zeros. They can be displayed that way in Access and other programs, but the
don't really have the zeros.

I have never had the need so I don't have any experience doing this.
There may well be a way of creating an output to a text file with leading
zeros, but you may need to change the field type to text.

I wonder if it might be easier to add the zeros back in the destination
program.
 
The Format Function affects the way values are DISPLAYED, but not the way
they are stored. Leading zeros, in other words, only exist in text strings.

You can use the CStr function to coerce the data type for export.
CStr(Right("00000" & [YourNumberField]))
 
Thanks a veriation on this worked well.

Jeff

Grover Park George said:
The Format Function affects the way values are DISPLAYED, but not the way
they are stored. Leading zeros, in other words, only exist in text strings.

You can use the CStr function to coerce the data type for export.
CStr(Right("00000" & [YourNumberField]))

--
George Hepworth
2007 Access MVP
Jeff Mc said:
I need to add zeros to the leading part of a number that I'm exporting.
The
numbers are being exported as text and have three or four digits. i.e.
"845"
or "1435" I need to have them export as "00000845" or "00001435". Seems
like it should be easy but I'm going in circles. Any suggestions would be
greatly appreciated.

P.S. I am a geek (Network Engineer) but not a programmer so be gentle.
 
I am exporting to a text file (.csv) that needs to be in a specific format to
imported into a payroll system.

I have an answer. But thanks for your interest.

Jeff
 
The format function returns a string:

"Returns a Variant (String) containing an expression formatted according to
instructions contained in a format expression."

It has nothing to do with the way values are DISPLAYED or STORED.

MH

Grover Park George said:
The Format Function affects the way values are DISPLAYED, but not the way
they are stored. Leading zeros, in other words, only exist in text
strings.

You can use the CStr function to coerce the data type for export.
CStr(Right("00000" & [YourNumberField]))

--
George Hepworth
2007 Access MVP
Jeff Mc said:
I need to add zeros to the leading part of a number that I'm exporting.
The
numbers are being exported as text and have three or four digits. i.e.
"845"
or "1435" I need to have them export as "00000845" or "00001435". Seems
like it should be easy but I'm going in circles. Any suggestions would be
greatly appreciated.

P.S. I am a geek (Network Engineer) but not a programmer so be gentle.
 

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

Back
Top