Results 1 to 6 of 6
  1. #1
    vorstopzolder is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    3

    More than one middle name


    I have a question about middle names. I don't know if I'm searching with the wrong keywords but I can't find an answer. I have a table with the next fields: surname, middlenames and name. I made a report where I combine all three of them like this:

    Code:
     
    =([name] & (" "+[middlenames]) & " " & [surname])
    It works perfectly with names like "Celia Cruz" or "Jack the Ripper". But it doesn't work with names with more than one middle name like "Celia de la Cruz", because the result in my report will be: "Celia de Cruz". The problem is that the expressions checks for white spaces en cuts the string if it finds one.

    Does somebody know what I can do about it?
    Thanks in advance.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you can use a function, or you might use an IIF statement in the source of the box.

    if this is a field that is displaying one per record on a report, IIF might be better than a function call, because it is instantaneous where a function is not.

  3. #3
    vorstopzolder is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    3
    Good advise! This is my solution and it works:

    Code:
    =([name] & (" "+(IIf([middlenames]=Null;Null;[middlenames]))) & " " & [surname])
    I don't know exactly why it works because if middlenames is not null and the middle name is "de la", there is still a white space?!? But it works. That's great.

    Thank you

  4. #4
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    The correct one should be refined as
    Code:
    =([name] & ((IIf([middlenames]=Null;Null;" "+[middlenames]))) & " " & [surname])

  5. #5
    vorstopzolder is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    3
    Thanks, makes more sense indeed. Is it possible that this expression doesn't work if you put more records of the same table in one report?

    I use this file on three different computers (Access 2007 and 2003). I made this DB at home (Access 2007) and it's saved as a 2003 file. But if a use it on my computer at work (also 2007) I have to change ";" to "," in the IIF expression. If not, I get an error. And this is just one example (there's more that works differently). Any idea why?

  6. #6
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    By the way, the syntax of separator of iif is "," instead of ";"
    It just happens that it does not warn for error.

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

Similar Threads

  1. Changing color in middle of email message
    By tgavin in forum Programming
    Replies: 5
    Last Post: 11-30-2010, 01:19 PM
  2. how select middle characters on string ???
    By ayman.maher in forum Queries
    Replies: 1
    Last Post: 04-27-2010, 09:29 AM
  3. Extract text from middle of a field
    By AccessNubie in forum Access
    Replies: 3
    Last Post: 11-02-2009, 01:13 PM

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