Results 1 to 9 of 9
  1. #1
    bruegel is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2012
    Location
    London
    Posts
    40

    Extraneous character in Concatenation

    I have a simple concatenation in a query listing writers of projects e.g. Writer 2 Name: [Writer 2 LN] & ", " & [Writer 2 FN 2]

    which takes Albert and Hall to give me Hall, Albert. However if there is only a single writer and no writer 2, 3 etc. then I get a field with no name but still with the comma. I'm trying to find a way of saying 'if there is no Writer 2 then leave the field completely empty' but I'm tying myself into knots and writing longer and longer statements. I feel there should be a simple way to do this but darned if I can find it.

    Solution gratefully sought

    Pieter

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Have you tried something like below :

    Code:
    IIf(IsNull([Writer 2 FN2]),[Writer 2 FN],[Writer 2 FN] & ", " & [Writer 2 FN2]) AS [Writer 2 Name]
    Thanks

  3. #3
    bruegel is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2012
    Location
    London
    Posts
    40
    I've been playing around with similar if maybe not exactly the same - got invalid syntax for your suggestion I'm afraid

    Pieter

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try this:

    [Writer 2 LN] & (", " + [Writer 2 FN 2])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    bruegel is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2012
    Location
    London
    Posts
    40
    Still getting that single comma in otherwise empty field unfortunately

    Pieter

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That means the field isn't necessarily Null. I don't think there was anything wrong with recyan's formula, but it was in SQL view where what you posted was design view. Try this:


    [Writer 2 Name]: IIf(Nz([Writer 2 FN2], "") = "",[Writer 2 FN],[Writer 2 FN] & ", " & [Writer 2 FN2])

    The spaces in your names aren't worth the trouble in the long run, and it appears you have a normalization problem with the multiple fields for the same type of value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    bruegel is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2012
    Location
    London
    Posts
    40
    I am going to close this thread as I realise that I made a typo in my original post. Thanks for help and fulsome apologies for my carelessness. Will play around with solutions but may repost if I am getting nowhere and hope for your tolerance. Many thanks. Pieter

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem Pieter.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    bruegel is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2012
    Location
    London
    Posts
    40
    I solved this by using a combination of the two answers, using an IsNull function but closer to the syntax of pbaldy's solution. Because of my typo I don't think it would help to post the sql here. If someone has the same dilemma they can contact me direct.

    Regarding the spaces. Unfortunately the data was imported from a very large spreadheet that didn't use databse field name conventions and had to be exported again to a similarly ill named spreadsheet. If I had constructed the db from scratch I would have observed conventions but renaming the whole thing twice was just too much like hard (and utimately unrewarding) work.

    Thanks for the help

    Pieter

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

Similar Threads

  1. Field concatenation
    By Trojnfn in forum Access
    Replies: 1
    Last Post: 10-10-2011, 05:56 PM
  2. Query and Concatenation
    By Try2Live4God in forum Programming
    Replies: 2
    Last Post: 05-25-2010, 03:45 PM
  3. Concatenation of Text and Number
    By diane802 in forum Reports
    Replies: 67
    Last Post: 01-26-2010, 03:37 PM
  4. Concatenation and IIF statements in report
    By bjsbrown in forum Reports
    Replies: 20
    Last Post: 10-19-2009, 10:00 AM
  5. Concatenation Urgent Help
    By Shoaib in forum Queries
    Replies: 0
    Last Post: 04-23-2009, 11:02 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