Mailing Address

R

Roger Bell

I have the following text box on a form:

=Trim([titles] & " " & [firstname]) & " " & [lastname] & Chr(13) & Chr(10) &
Trim([unit/flat] & " " & [unit/flat no] & Chr(13) & Chr(10) & "" & ([street
number] & "" & [street prefix] & " " & [street name]) & Chr(13) & Chr(10) &
Trim([suburb] & " " & [state] & " " & [pcode]))

What I would like is when there is no Unit/Flat, then this line space will
be closed up. Could someone kindly advise how this can be achieved?
 
J

John W. Vinson

I have the following text box on a form:

=Trim([titles] & " " & [firstname]) & " " & [lastname] & Chr(13) & Chr(10) &
Trim([unit/flat] & " " & [unit/flat no] & Chr(13) & Chr(10) & "" & ([street
number] & "" & [street prefix] & " " & [street name]) & Chr(13) & Chr(10) &
Trim([suburb] & " " & [state] & " " & [pcode]))

What I would like is when there is no Unit/Flat, then this line space will
be closed up. Could someone kindly advise how this can be achieved?

There's a sneaky way to do it, using the fact that both the & and + operators
concatenate strings. They do it differently: & treats a NULL value as an empty
string - e.g. [FieldA] & [FieldB] returns the value in fieldA if fieldB is
null; + propagates nulls, so that [FieldA] + [FieldB] is NULL if either one is
null.

Secondly, you don't need TRIM unless you have leading blanks... and the same
trick can get rid of them.

Try

([titles] + " ") & [firstname] & " " & [lastname] & Chr(13) & Chr(10) &
([unit/flat] + " " + [unit/flat no] + Chr(13) & Chr(10)) & ([street
number] & ([street prefix] + " ") & [street name] & Chr(13) & Chr(10) &
([suburb] + " ") & [state] & " " & [pcode]

Just for example, if [Titles] contains "Mr." the first parenthetical
expression will resolve to "Mr. " (appending the blank); if there is nothing
in Titles, the expression will be NULL and the first line will start with the
first name.
 
R

Roger Bell

Thanks for you help, John.

Tried that, but get an error saying "Extra) in query expression"

Please help if you are able

John W. Vinson said:
I have the following text box on a form:

=Trim([titles] & " " & [firstname]) & " " & [lastname] & Chr(13) & Chr(10) &
Trim([unit/flat] & " " & [unit/flat no] & Chr(13) & Chr(10) & "" & ([street
number] & "" & [street prefix] & " " & [street name]) & Chr(13) & Chr(10) &
Trim([suburb] & " " & [state] & " " & [pcode]))

What I would like is when there is no Unit/Flat, then this line space will
be closed up. Could someone kindly advise how this can be achieved?

There's a sneaky way to do it, using the fact that both the & and + operators
concatenate strings. They do it differently: & treats a NULL value as an empty
string - e.g. [FieldA] & [FieldB] returns the value in fieldA if fieldB is
null; + propagates nulls, so that [FieldA] + [FieldB] is NULL if either one is
null.

Secondly, you don't need TRIM unless you have leading blanks... and the same
trick can get rid of them.

Try

([titles] + " ") & [firstname] & " " & [lastname] & Chr(13) & Chr(10) &
([unit/flat] + " " + [unit/flat no] + Chr(13) & Chr(10)) & ([street
number] & ([street prefix] + " ") & [street name] & Chr(13) & Chr(10) &
([suburb] + " ") & [state] & " " & [pcode]

Just for example, if [Titles] contains "Mr." the first parenthetical
expression will resolve to "Mr. " (appending the blank); if there is nothing
in Titles, the expression will be NULL and the first line will start with the
first name.
 
J

John W. Vinson

Thanks for you help, John.

Tried that, but get an error saying "Extra) in query expression"

Please help if you are able

Sorry about the typo. Did you try counting parentheses yourself to see where I
made a mistake? The trick I use is to count left to right adding 1 for each
left paren and subtracting 1 for each right: let's try it...

([titles] + " ") & [firstname] & " " & [lastname] & Chr(13) & Chr(10) &
([unit/flat] + " " + [unit/flat no] + Chr(13) & Chr(10)) & [street
number] & ([street prefix] + " ") & [street name] & Chr(13) & Chr(10) &
([suburb] + " ") & [state] & " " & [pcode]


ok, there was an extra ( in front of [Street Number].
 
R

Roger Bell

Thanks again John,

Have altered as follows, but still receiving the Extra) error message. Have
counted for 4( & 4) as kindly suggested

([titles]+" ") & [Firstname] & " " & [Lastname] & Chr(13) & Chr(10) &
([unit/flat]+" "+[unit/flat no]+Chr(13) & Chr(10)) & [street number] &
([street prefix]+" ") & [street name] & Chr(13) & Chr(10) & ([suburb]+" ") &
[state] & " " & [pcode]

Any thoughts



John W. Vinson said:
Thanks for you help, John.

Tried that, but get an error saying "Extra) in query expression"

Please help if you are able

Sorry about the typo. Did you try counting parentheses yourself to see where I
made a mistake? The trick I use is to count left to right adding 1 for each
left paren and subtracting 1 for each right: let's try it...

([titles] + " ") & [firstname] & " " & [lastname] & Chr(13) & Chr(10) &
([unit/flat] + " " + [unit/flat no] + Chr(13) & Chr(10)) & [street
number] & ([street prefix] + " ") & [street name] & Chr(13) & Chr(10) &
([suburb] + " ") & [state] & " " & [pcode]


ok, there was an extra ( in front of [Street Number].
 
J

John W. Vinson

Thanks again John,

Have altered as follows, but still receiving the Extra) error message. Have
counted for 4( & 4) as kindly suggested

([titles]+" ") & [Firstname] & " " & [Lastname] & Chr(13) & Chr(10) &
([unit/flat]+" "+[unit/flat no]+Chr(13) & Chr(10)) & [street number] &
([street prefix]+" ") & [street name] & Chr(13) & Chr(10) & ([suburb]+" ") &
[state] & " " & [pcode]

Count the entire query. I can't see it from here.
 

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

Similar Threads

Mailing Address 3
Address Envelope with Trim 1
Address 1
Labels 4
Sorting a concatenated query problem 7
Set focus on a different Form 1
Mailing Labels 3
concatenated address fields 5

Top