Connecting Tech Pros Worldwide Forums | Help | Site Map

Left Padding of "0" in String

overcomer's Avatar
Newbie
 
Join Date: Nov 2008
Location: Manila
Posts: 25
#1: Nov 13 '08
Hi....

Please advise on how to create dynamic left padding for string... thanks to you..

Also, if anyone could add any idea of cascading combo box as it's not possible to setup rowsource in vba.

syntax for access 2003 can be ...

thanks so much

missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,000
#2: Nov 13 '08

re: Left Padding of "0" in String


Padding a number with leading zeros can be done using the Format() function:

Format(YourNumericField, "0000")

8 will be returned as 0008, 12 as 0012 and so forth.

Note that Format() actually returns a string/text value. Access is often forgiving when dealing with this kind of thing. If, for example

YourNumericField

equals 10

and in VBA code you use the formula

NewNumber = Format(YourNumericField, "0000") * 12

Access will correctly calculate NewNumber as 120.

If you try to use

Format(YourNumericField, "0000")

and get an "Error 13 - Type Mismatch" error, wrap the function like this

Val(Format(YourNumericField, "0000"))

Quote:

Originally Posted by overcomer

If anyone could add any idea of cascading combo box as it's not possible to setup rowsource in vba.

***Why*** can't you set the Row Source in VBA? It doesn't require a lot of code, but I know of no way to set up cascading comboboxes using no code at all.

Welcome to Bytes!

Linq ;0)>
overcomer's Avatar
Newbie
 
Join Date: Nov 2008
Location: Manila
Posts: 25
#3: Nov 19 '08

re: Left Padding of "0" in String


Hi,

thanks for the reply... i already have the solutions for both questions... thanks a lot... :)
Reply