MSAccess VBA: How to display number with preceding 0?
I have the following zip codes in a linked table. My query pulls from this linked table.
01234
00123
12345
12345-6789
Problem: The preceding zeros ar开发者_StackOverflow中文版e truncated.
I have tried adding an apostrophe to convert to string: ="'" & [PCode]
But that is not a nice solution.
Please help. Thanks.
Format should suit:
p="12345-6789"
?Format(p,"00000")
12345-6789
p="123"
?Format(p,"00000")
00123
However, if you have a number longer than 5 digits that requires preceding zeros, you will need an IIF:
p="123-6789"
?Format(p,"00000")
123-6789
Postal Code: IIf([PCode] Like "####","0" & [PCode],IIf([PCode] Like "#####-",Left([PCode],Len([PCode])-1),IIf([PCode] Like "#########",Format([PCode],"@@@@@-@@@@"),[PCode])))
精彩评论