Right Justify text

M

Mark Parent

Is there an easier way to extract and right justify a number from a string?

I'm pulling the "BRANCH" value from a longer string and formating it using:
BRANCH =
Format(Val(Left([Branch_Account_Num],Len([Branch_Account_Num])-[Posn])),"#")

and want to right justify the result within another string. Do I need to use:
space(10-len([BRANCH]) & [BRANCH] ?

I keep thinking there must be a custom formating that I could use instead of
"#" that would do this, but I can't find it...
 
V

vanderghast

Numbers are right justified, strings are left justified. Changing your
number into a string:

myNumber & ""

should do, to get a left justification.


Vanderghast, Access MVP
 
M

Mark Parent

I'm looking for RIGHT JUSTIFIED. [BRANCH] is "b123", and I want to see
"bbbbbbb123", so I'm using SPACE(10-len([BRANCH])) & [BRANCH] and it works,
but seems inefficient.

When I pull BRANCH from it's original string, I'm formatting it as a number
to get a value that's trimmed of leading and trailing blanks, but is there a
way to format it right justified into a (for example) 10 character string in
the same step?


vanderghast said:
Numbers are right justified, strings are left justified. Changing your
number into a string:

myNumber & ""

should do, to get a left justification.


Vanderghast, Access MVP


Mark Parent said:
Is there an easier way to extract and right justify a number from a
string?

I'm pulling the "BRANCH" value from a longer string and formating it
using:
BRANCH =
Format(Val(Left([Branch_Account_Num],Len([Branch_Account_Num])-[Posn])),"#")

and want to right justify the result within another string. Do I need to
use:
space(10-len([BRANCH]) & [BRANCH] ?

I keep thinking there must be a custom formating that I could use instead
of
"#" that would do this, but I can't find it...
 
J

John Spencer

You could use

Right(Space(10) & [Branch],10)

but that is probably no more efficient than what you have. On the other hand
it will handle nulls, which I don't think your expression will.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Mark said:
I'm looking for RIGHT JUSTIFIED. [BRANCH] is "b123", and I want to see
"bbbbbbb123", so I'm using SPACE(10-len([BRANCH])) & [BRANCH] and it works,
but seems inefficient.

When I pull BRANCH from it's original string, I'm formatting it as a number
to get a value that's trimmed of leading and trailing blanks, but is there a
way to format it right justified into a (for example) 10 character string in
the same step?


vanderghast said:
Numbers are right justified, strings are left justified. Changing your
number into a string:

myNumber & ""

should do, to get a left justification.


Vanderghast, Access MVP


Mark Parent said:
Is there an easier way to extract and right justify a number from a
string?

I'm pulling the "BRANCH" value from a longer string and formating it
using:
BRANCH =
Format(Val(Left([Branch_Account_Num],Len([Branch_Account_Num])-[Posn])),"#")

and want to right justify the result within another string. Do I need to
use:
space(10-len([BRANCH]) & [BRANCH] ?

I keep thinking there must be a custom formating that I could use instead
of
"#" that would do this, but I can't find it...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top