Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Consolidating address fields where some elements are blank

Consolidating address fields where some elements are blank

Consolidating address fields where some elements are blank

I am revising an often used report for marketing purposes, but have an issue with the address fields.

Our database stores addresses based on the following fields, with:


When extracting data for mailing etc, I want to use formulas for each line of the address so as to consolidate the data, so that if any of the fields are blank, I can in its place display the NEXT populated address field, so as to avoid blank lines in full addresses.

For example, if the following is in the database:

{cusmast.cm_address_1} = 1 Smith Road
{cusmast.cm_address_2} =
{cusmast.cm_address_3} =
{cusmast.cm_address_4} = Anytown
{cusmast.cm_address_5} = AnyState

I can get the following output:

Address line 1 = 1 Smith Road
Address line 2 = Anytown
Address line 3 = AnyState
Address line 4 =
Address line 5 =

I have tried any number of If/ELSE structures, but can't get it to work for anything other than checking the next line if the field being checked ISNULL.

Can anyone help by suggesting a simple forumla that I can use for each address line so as to achieve the desired outcome?

Thanks in advance

RE: Consolidating address fields where some elements are blank

I'm guessing that {cusmast.cm_address_1} always has something in it?
Try this {cusmast.cm_address_1} &
If(Trim({cusmast.cm_address_2}) > " " Then " " & Trim({cusmast.cm_address_2}) Else "" &
If(Trim({cusmast.cm_address_3}) > " " Then " " & Trim({cusmast.cm_address_3}) Else "" &
If(Trim({cusmast.cm_address_4}) > " " Then " " & Trim({cusmast.cm_address_4}) Else "" &
If(Trim({cusmast.cm_address_5}) > " " Then " " & Trim({cusmast.cm_address_5}) Else ""

RE: Consolidating address fields where some elements are blank

You will need to check for both empty strings and null values. Null values will cause the formula to fail, and empty strings (or those with only spaces) will cause blank lines to appear.

Try this formula (which also assumes line 1 will always contain data - if not you will also need to add a test for that field):


{cusmast.cm_address_1} +
    If      NOT (Isnull({cusmast.cm_address_2})) and
            Trim({cusmast.cm_address_2}) <> ''
    Then    CHR(10) + {cusmast.cm_address_2}
    Else    '';
    If      NOT (Isnull({cusmast.cm_address_3}))and
            Trim({cusmast.cm_address_3}) <> ''
    Then    CHR(10) + {cusmast.cm_address_3}
    Else    '';
    If      NOT (Isnull({cusmast.cm_address_4}))and
            Trim({cusmast.cm_address_4}) <> ''
    Then    CHR(10) + {cusmast.cm_address_4}
    Else    '';
    If      NOT (Isnull({cusmast.cm_address_5}))and
            Trim({cusmast.cm_address_5}) <> ''
    Then    CHR(10) + {cusmast.cm_address_5}
    Else    '';

Hope this helps.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close