Results 1 to 6 of 6
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Handling Null In Concatenation

    Let's say I have 3 fields, FirstName, MiddleName, LastName and I want to concatenate them into one


    Code:
    FullName: [FirstName] & " " & [MiddleName] & " " & [LastName]
    Well what if middle name was blank? I wouldn't want my output to be: FirstName LastName, that would be odd, how can I handle Null values in concatenation of strings like such?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Try:

    FullName: [FirstName] & " " + [MiddleName] & " " & [LastName]
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    JeffChr is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    82
    If you are doing this in a query then it will work as written, except you will have two spaces between the names if the middle name is written. You can correct that: FullName: Replace([FirstName] & " " & [MiddleName] & " " & [LastName]," "," ")

  5. #5
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Quote Originally Posted by June7 View Post
    Try:

    FullName: [FirstName] & " " + [MiddleName] & " " & [LastName]
    So what is the difference between the & and + sign between the concatenation?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Test it in the VBA immediate window by typing:

    ?"A" & " " & Null & " " & "B"

    ?"A" & " " + Null & " " & "B"

    The first will return 2 spaces between.

    The second will not.

    + sign has two uses: addition and concatenation. The concatenation use is holdover from ancient BASIC.

    Anyway, arithmetic with Null returns null. So the " " + Null returns Null instead of the space.

    Then Null is just ignored with the & concatenation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Concatenation
    By lantoni in forum Access
    Replies: 31
    Last Post: 03-06-2014, 07:29 AM
  2. Null handling in access database
    By BatmanMR287 in forum Access
    Replies: 15
    Last Post: 01-13-2014, 03:20 PM
  3. Concatenation
    By Rhubie in forum Access
    Replies: 3
    Last Post: 08-30-2012, 05:09 PM
  4. Handling Null DLookup result
    By j6sander in forum Access
    Replies: 1
    Last Post: 07-19-2012, 11:07 AM
  5. Help with Null value handling
    By Thumbs in forum Programming
    Replies: 3
    Last Post: 03-05-2012, 10:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums