Leading Zeros

M

murfitUK

Using Access 2000 on Windows XP Home.

I have created a field which will contain an item's code. The code is a
four digit number but can start with a zero.

In the table design, the field is set up as: Data Type = Number and Field
Size = Long Integer. But if I enter, eg, 0376 it comes up as 376.

How can I get it to display 0376 instead of 376?

I thought about changing it to a simple text field but I hit a problem when
sorting the records into numerical order.

Thanks for your help.
 
D

Douglas J. Steele

If you only care about it for display purposes, set the Format property to
0000
 
F

fredg

Using Access 2000 on Windows XP Home.

I have created a field which will contain an item's code. The code is a
four digit number but can start with a zero.

In the table design, the field is set up as: Data Type = Number and Field
Size = Long Integer. But if I enter, eg, 0376 it comes up as 376.

How can I get it to display 0376 instead of 376?

I thought about changing it to a simple text field but I hit a problem when
sorting the records into numerical order.

Thanks for your help.

You can set the Format property of the number control to
0000
to display a number as 0376.

However, if the field is not going to be used in numeric calculations,
it should be a Text datatype field. All you need do, in the entry
form, is code the After Update event of the control to:

[ThisControl] = Format([ThisControl],"0000")

It will now be stored as a 4 character string, with leading zeros, and
sort as though it was a number, with no additional formatting needed
if used elsewhere.
 
Top