I would like to pad a text field (Address - lngth 50) with spaces, so that I can easily export to a fixed length text file.
What format/padding options are there within a field in an Access 2002 table?
' Try this. Untested but simple
Function PadLeft(strIn as string, _
byVal lngPad as long, _
Optional Byval strPadChar as string=" " as string
Dim L As Long
strPadChar = Left(strPadChar,1)
L = Len)strIN)
if Len(strPadChar) < 1 then exit sub
if L >= lngPad then exit sub
PadLeft = String(lngPad - L, strPadChar) & strIn
End Function
Function PadRight(strIn as string, _
byVal lngPad as long, _
Optional Byval strPadChar as string=" " as string
Dim L As Long
strPadChar = Left(strPadChar,1)
L = Len)strIN)
if Len(strPadChar) < 1 then exit sub
if L >= lngPad then exit sub
PadRight = strIn & String(lngPad - L, strPadChar)
End Functiion
If you are exporting a fixed-length file, you don't have to worry about padding. Just define an export specification with the Address field 50 characters long and don't let the next field start until 50 characters past the start of the Address field.
If the Address field is the last field in the record, even adding padding to the field will not save the spaces. Trailing spaces in an ASCII record are trimmed automatically.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.