How to return a Padded String with Blanks on Left
Posted on January 4, 2009
1 2 3 4 5 6 | 'String Manipulation - How to return return a Padded String with Blanks on Left Option Explicit Public Function PadL(ByVal strExpression As String, ByVal iWidth As Integer) As String PadL = Right(Space(iWidth) & RTrim(strExpression), iWidth) End Function |
June 11th, 2009 - 15:27
Thanks for this Function. For a specific application, I needed to add leading zeros to a numeric string and couldn’t believe MS Access doesn’t have a built-in function for this. I changed your function as follows for my purposes:
Public Function PadL(ByVal strExpression As String, ByVal iWidth As Integer) As String
PadL = String(iWidth – Len(strExpression), “0″) & RTrim(strExpression)
End Function
Simple and works like a champ.
June 11th, 2009 - 18:53
You can use format function to add leading 0′s. Try it and let us know.