Found this handy little tip in the "archives" ...
Here's a slick way to format a numeric field with leading zeros - works like a charm!
Say you have a long field where the maximum value can be, say, 9999. Your number is 47, so you need your output to read 0047 ...
Simply add 10000 to your number, and take the right 4 digits of the new number, such as follows:
You can break this down even farther, and do the whole thing in one line!
Hoping this little method helps you out ...
Greg
Here's a slick way to format a numeric field with leading zeros - works like a charm!
Say you have a long field where the maximum value can be, say, 9999. Your number is 47, so you need your output to read 0047 ...
Simply add 10000 to your number, and take the right 4 digits of the new number, such as follows:
Code:
Dim MyNum As Long
Dim MyNewNum As Long
Dim MyFormattedNum As String
MyNum = 47
MyNewNum = 10000 + MyNum
MyFormattedNum = Right(CStr(MyNewNum), 4)
Code:
MyFormattedNum = Right(Cstr(MyNum + 10000), 4)
Greg