Robert Stewart
rls at WeBeDb.com
Tue Jun 7 11:06:43 CDT 2011
Here is a somewhat elegant way of handling all of your padding needs.
Public Function udfPadString(ByVal strToPad As String, ByVal
intLength As Integer, ByVal strPadWith As String, ByVal strWhichSide
As String) As String
Dim strReturnValue As String
Dim intPaddingNeeded As Integer
Dim intCount As Integer
' check the length of the string to see if it is eaual to or longer than
' the specified length that was passed in
If Len(strToPad) >= intLength Then udfPadString = strToPad
intPaddingNeeded = intLength - Len(strToPad)
strReturnValue = strToPad
If strWhichSide = "L" Then
For intCount = 1 To intPaddingNeeded
strReturnValue = strPadWith & strReturnValue
Next intCount
Else
For intCount = 1 To intPaddingNeeded
strReturnValue = strReturnValue & strPadWith
Next intCount
End If
udfPadString = strReturnValue
End Function
At 06:52 PM 6/6/2011, you wrote:
>Date: Mon, 6 Jun 2011 18:52:31 -0500
>From: Debbie <delam at zyterra.com>
>To: Access Developers discussion and problem solving
> <accessd at databaseadvisors.com>
>Subject: Re: [AccessD] How to right justify numeric fields and pad
> with spaces on the left.
>Message-ID: <5C91B293-B889-4D67-9D13-59B3E63E634D at zyterra.com>
>Content-Type:
>text/plain; charset=us-ascii; format=flowed; delsp=yes
>
>When I needed to do this, I made a function that i passed the string
>and the number of total chars needed. It would loop through until the
>length was the number of chars and would add a space ( or in my case a
>0) to the beginning of the string.
>
>Debbie
>
>Sent from my iPhone
>
>On Jun 6, 2011, at 4:12 PM, "Brad Marks" <BradM at blackforestltd.com>
>wrote:
>
> > We are using Access 2007 to create an output file for another firm.
> >
> > The specs for this file are dictated by the other firm.
> >
> > The specs call for numeric fields to be right justified and padded
> > with
> > spaces on the left.
> >
> > What is the best way to do this with Access 2007?
> >
> > Thanks,
> > Brad
Robert L. Stewart
www.WeBeDb.com
www.DBGUIDesign.com
www.RLStewartPhotography.com