How to have report text shift left ? (Fname MI Lname)

W

Will

When creating a report we want the Fname MI Lname to shift left and not be
spaced out...

Not Like...

John A Smith

But like...

John A. Smith.

I looked at properties for the fields on the report but need guidance.

thanks for any help.
 
B

Bob Quintal

When creating a report we want the Fname MI Lname to shift left
and not be spaced out...

Not Like...

John A Smith

But like...

John A. Smith.

I looked at properties for the fields on the report but need
guidance.

thanks for any help.
The way most developers do this is to put an unbound textbox on the
report, and set the control source of that box
= Fname+" " & MI + ". " & Lname
 
J

John W. Vinson

The way most developers do this is to put an unbound textbox on the
report, and set the control source of that box
= Fname+" " & MI + ". " & Lname

nitpick: use & instead of + - the + operator propagates NULLS so it would make
the whole string blank if there were no MI.

Or better,

[FName] & " " & ([MI] + ". ") & [LName]

to get "Jim Smith" instead of "Jim . Smith" if there is no MI.

John W. Vinson [MVP]
 
B

Bob Quintal

The way most developers do this is to put an unbound textbox on
the report, and set the control source of that box
= Fname+" " & MI + ". " & Lname

nitpick: use & instead of + - the + operator propagates NULLS so
it would make the whole string blank if there were no MI.

Or better,

[FName] & " " & ([MI] + ". ") & [LName]

to get "Jim Smith" instead of "Jim . Smith" if there is no MI.

John W. Vinson [MVP]
John, +" " & in my code does exatly what you suggest if FName is
null. Have you found the parentheses necessary, my example seems
works without them.
 
J

John W. Vinson

[FName] & " " & ([MI] + ". ") & [LName]

to get "Jim Smith" instead of "Jim . Smith" if there is no MI.

John W. Vinson [MVP]
John, +" " & in my code does exatly what you suggest if FName is
null. Have you found the parentheses necessary, my example seems
works without them.

The parentheses *are* necessary. If FName can be null (I didn't account for
that!) you should in fact use

([FName] + " ") & ([MI] + ". ") & [LName]

The logic is that anything + NULL is NULL; so if FName is null, the expression
[FName] + Null

will be NULL. The & operator treats NULL as if it were an empty string, so by
putting the + expression in parentheses, a null FName doesn't drag along an
extra blank.

I'm not sure about the precedence of + and & - you might be able to get by
without the parentheses if the + operator is processed first, but they don't
hurt and make the order of operations explicit.

John W. Vinson [MVP]
 
B

Bob Quintal

[FName] & " " & ([MI] + ". ") & [LName]

to get "Jim Smith" instead of "Jim . Smith" if there is no MI.

John W. Vinson [MVP]
John, +" " & in my code does exatly what you suggest if FName is
null. Have you found the parentheses necessary, my example seems
works without them.

The parentheses *are* necessary. If FName can be null (I didn't
account for that!) you should in fact use

([FName] + " ") & ([MI] + ". ") & [LName]

The logic is that anything + NULL is NULL; so if FName is null,
the expression [FName] + Null

will be NULL. The & operator treats NULL as if it were an empty
string, so by putting the + expression in parentheses, a null
FName doesn't drag along an extra blank.

I'm not sure about the precedence of + and & - you might be able
to get by without the parentheses if the + operator is processed
first, but they don't hurt and make the order of operations
explicit.

John W. Vinson [MVP]

I believe that the + and & concatenation operators are equal in
precedence and the expression is simply evaluated left to right.

The parenteses are therefor superfluous.
([FName] + " ") & ([MI] + ". ") & [LName]
and FName + " " & MI + ". " & LName
are in every case equivalent. They also take equal time.

Interestingly, if MI is null, the process takes 8% longer
 
J

John W. Vinson

I believe that the + and & concatenation operators are equal in
precedence and the expression is simply evaluated left to right.

The parenteses are therefor superfluous.
([FName] + " ") & ([MI] + ". ") & [LName]
and FName + " " & MI + ". " & LName
are in every case equivalent. They also take equal time.

Interestingly, if MI is null, the process takes 8% longer

Cool! Thanks for digging into this - I've never really investigated it.

John W. Vinson [MVP]
 

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