Keep the leading zeros

  • Thread starter Thread starter Rog
  • Start date Start date
R

Rog

I have a field that increments by 10 for each record.
The problem I'm having is that the field needs to be 4
digits long.

So it would need to display 0010, 0020, 0100, 1000, etc.

I have the field formatted to number.

How do I hold on to the leading zeros, so it doesn't crop
0010 to 10?

Thanks.
 
If you only care about displaying leading zeros, open the table in design
view, select the field, and in the lower pane set the Format property ot:
0000

If you want to store the leading zeros (e.g. so you can have one field
containing 010 and another 0010 without them being considered duplicates),
open the table in design view and change the Field Type to Text.
 
Dear Rog:

When you want to display the string, use this:

Right("000" & CStr(YourField), 4)

This says to convert the number to a string, add 3 zeros on the left
side, then take the rightmost 4 characters. Should do the trick.

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