format conversion from numeric to string

  • Thread starter Thread starter jerome
  • Start date Start date
J

jerome

Is there a way to convert numeric value to a string value
WITH a given number of leading 0 ?
for instance : 12 converted in "0012"
thanks for any help
 
Thank you for your quick answer.
But my problem is that when I use the Cstr SQL statement,
I don't know the length of the returned string...
is it possible to include in the SQL query something like
"iif len(Cstr(numvalue),2, "00"& Cstr(numvalue)) else iif
len(Cstr(numvalue),3, "000"& Cstr(numvalue))"
etc...
Thank you for your help
Jérôme
 
Dear Jerome:

Assuming the result will never require more than 4 digits, you can use
this:

RIGHT("000" & CStr(YourValue), 4)

To allow for more than 4 digits, increase the number of zeroes and
select a longer string, e.g.:

RIGHT("0000" & CStr(YourValue), 5)

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Back
Top