Results 1 to 10 of 10
  1. #1
    Dean0_53 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    30

    Trim Middle name

    Hello,

    Is there an easy way to trim out a middle name and only have middle initial with a period? My next question is, what happens if there is not middle name? I tried doing a left function, but I couldn't get it to work.

    ([LAST_NAME ] & ' ' & [FIRST_NAME]) & ' ' & (' '+[MI]+' ')




    Thanks,
    Deano

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    Hi Deano

    Are you Russ by any chance?
    Use Nz function

    ([LAST_NAME ] & ' ' & [FIRST_NAME]) & Nz(' ' & [MI],'')
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Have the right idea of using + for concantenation. It's a weird quirk of the + symbol. Using it for concatenation is holdover from ancient BASIC. Also, using + with Null returns Null.

    ([LAST_NAME ] & " " & [FIRST_NAME]) & " " + Left([MIDDLE_NAME],1) + "."

    Now I see ridders52 suggestion. That expression with ' ' & will never return Null. Nz is not needed.
    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
    Join Date
    Apr 2017
    Posts
    1,776
    Maybe
    Code:
    ([LAST_NAME ] & " " & [FIRST_NAME]) & Trim(" " + Nz([MI],"")) & Iif(Nz([MI],"")="","",".") 
    is better (better is not to mess up different syntaxes - maybe OP needs to port the app to some other database in future).

  5. #5
    Dean0_53 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    30
    Hi ridders52.

    Nope, sorry my name isn't Russ.

  6. #6
    Dean0_53 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    30
    I'll take a look at this tomorrow am. Thanks for the suggestions!

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    Quote Originally Posted by June7 View Post
    Have the right idea of using + for concantenation. It's a weird quirk of the + symbol. Using it for concatenation is holdover from ancient BASIC. Also, using + with Null returns Null.

    ([LAST_NAME ] & " " & [FIRST_NAME]) & " " + Left([MIDDLE_NAME],1) + "."

    Now I see ridders52 suggestion. That expression with ' ' & will never return Null. Nz is not needed.
    1.
    using + with Null returns Null.
    Thanks - I didn't know that ...but then I never use + for concatenation

    2. You're of course right about my solution - my brain wasn't in gear
    This should do what I meant in the first place :
    Code:
    ([LAST_NAME ] & ' ' & [FIRST_NAME]) & IIf(Nz[MI],'')<>'',' ' & [MI],'')
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    Dean0_53 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    30
    Hey Guys,

    I found another table I can use but now I have a different problem. Some of the names from the table i'm using aren't coming into the final report. Also, is there a way to add a period to the Middle Initial? Please see my new expression below.

    Record Name: ([LAST_NAME ] & ' ' & [FIRST_NAME]) & ' ' & (' '+[MIDDLE_INITIAL]+' ')


    Thanks!

  9. #9
    Join Date
    Apr 2017
    Posts
    1,776
    Try
    Code:
     ([LAST_NAME ] & ' ' & [FIRST_NAME]) & ' ' & (' '+[MIDDLE_INITIAL]+'.')
    and even better will be
    Code:
     ([LAST_NAME ] & ' ' & [FIRST_NAME]) & (' '+[MIDDLE_INITIAL]+'.')
    as in your current expression when middle name is empty, a single space string is added after first name

  10. #10
    Dean0_53 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    30
    This is great!

    Thanks again for the help!

    Deano

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

Similar Threads

  1. Trim in middle of string
    By tmcrouse in forum Access
    Replies: 2
    Last Post: 12-22-2015, 09:11 AM
  2. Autonumber Coming from middle
    By drunkenneo in forum Programming
    Replies: 6
    Last Post: 10-22-2013, 02:51 PM
  3. Parsing Middle of String
    By OprEowyn in forum Queries
    Replies: 4
    Last Post: 02-20-2013, 10:53 PM
  4. Replies: 3
    Last Post: 05-08-2011, 12:55 PM
  5. More than one middle name
    By vorstopzolder in forum Access
    Replies: 5
    Last Post: 02-10-2011, 01:09 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