Keep the leading zeros

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.
 
A

Allen Browne

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.
 
T

Tom Ellison

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
 

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

Top