How to format a numeric field in Microsoft Access?

2019-09-09 09:46发布

问题:

I want a numeric field to be always displayed as a 3-digit number. Padded left with 0s as needed.

Example: 3 is shown as 003, 24 as 024 and so on. Assuming max number is 999.

How do I do so? Thanks.

回答1:

Function Lpad (Value as String, PadCharacter as String, PaddedLength as Integer)
    Lpad = string(PaddedLength - Len(Value), PadCharacter) & Value
End Function

Ref.

Lpad("3", "0", 3)