开发者

MSAccess VBA: How to display number with preceding 0?

开发者 https://www.devze.com 2023-04-12 07:58 出处:网络
I have the following zip codes in a linked table. My query pulls from this linked table. 01234 00123 12345

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])))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号