Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Padding Text Fields

Status
Not open for further replies.

Shfog

Programmer
Aug 24, 2001
20
US
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?

Thanks...
 
' 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=&quot; &quot;) 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 Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top