Results 1 to 11 of 11
  1. #1
    annaisakiwi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    8

    Post Combining fields - iif??

    Hi guys



    I'm setting up a contacts database.

    I have 4 fields:
    Name 1
    Name 2
    Surname
    Company Name

    What I would like to happen is:
    If all fields have data then, Name 1 & Name 2 Surname, Company Name
    If any of the fields are null - then don't enter them, if only Name 1 or Name 2 then won't need the & and if only the Company Name, won't need the , before it.

    Is anyone able to help me??

    Cheers Anna

  2. #2
    annaisakiwi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    8
    This is what I've got so far... although i think i'm totally mucking this up:

    Contact Name: IIf(IsNull([Name 1]),IIf(IsNull([Name 1]),[Surname],[Name 1]),IIf(IsNull([Name 1]),[Name 1],[Name 1] & " & " & [Name 2] & " " & [Surname]))

  3. #3
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Hi Anna,

    Try this:

    Code:
    Contact: IIf(IsNull([Name 1]) Or IsNull([Name 2]) Or IsNull([Surname]) Or IsNull([Company Name]),"",[Name 1] & " & " & [Name 2] & " " & [Surname] & ", " & [Company Name])
    Cheers,

  4. #4
    annaisakiwi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    8
    Quote Originally Posted by ConneXionLost View Post
    Hi Anna,

    Try this:

    Code:
    Contact: IIf(IsNull([Name 1]) Or IsNull([Name 2]) Or IsNull([Surname]) Or IsNull([Company Name]),"",[Name 1] & " & " & [Name 2] & " " & [Surname] & ", " & [Company Name])
    Cheers,
    Cheers that worked when all the fields are filled in :-)

    How do I get it so it combines the fields, even when one is empty thou? thanks heaps for the help - such a beginner!

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    How about this????

    Code:
    ContactName: nz([name1],"") & IIf(IsNull([name1]),""," ") & nz([name2],"") & IIf(IsNull([name2]),""," ") & nz([Surname],"") & IIf(IsNull([companyname]),"",", ") & Nz([companyname],"")
    You might have to edit this a little. I never use spaces in field names..... it causes too many problems.

  6. #6
    annaisakiwi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    8

    Smile

    Quote Originally Posted by ssanfu View Post
    How about this????

    Code:
    ContactName: nz([name1],"") & IIf(IsNull([name1]),""," ") & nz([name2],"") & IIf(IsNull([name2]),""," ") & nz([Surname],"") & IIf(IsNull([companyname]),"",", ") & Nz([companyname],"")
    You might have to edit this a little. I never use spaces in field names..... it causes too many problems.
    Wicked thats pretty much it! THANKS HEAPS!

    one little last question though... If there is a Name 1 and Name 2 - I want to put '&' inbetween them... is this possible? again thanks sooooo much for all the help.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    one little last question though... If there is a Name 1 and Name 2 - I want to put '&' inbetween them... is this possible? again thanks sooooo much for all the help.
    Yes, but you have to be able to define a rule to determine when you add the '&'.


    Hmmmm, maybe this:
    Code:
    ContactName2: nz([name1],"") & IIf(IsNull([name1]),"",IIf(IsNull([name2])," "," & ")) & nz([name2],"") & IIf(IsNull([name2]),""," ") & nz([Surname],"") & IIf(IsNull([companyname]),"",", ") & Nz([companyname],"")
    BTW, its not a good idea to use spaces in object names (field names, form names, query names,...) Use CamelBackNames....even there are 3 words run together, it is still easy to read. Spaces will cause you headaches down the road..

  8. #8
    annaisakiwi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    8
    Quote Originally Posted by ssanfu View Post
    Yes, but you have to be able to define a rule to determine when you add the '&'.


    Hmmmm, maybe this:
    Code:
    ContactName2: nz([name1],"") & IIf(IsNull([name1]),"",IIf(IsNull([name2])," "," & ")) & nz([name2],"") & IIf(IsNull([name2]),""," ") & nz([Surname],"") & IIf(IsNull([companyname]),"",", ") & Nz([companyname],"")
    BTW, its not a good idea to use spaces in object names (field names, form names, query names,...) Use CamelBackNames....even there are 3 words run together, it is still easy to read. Spaces will cause you headaches down the road..
    Again thanks so much! it's pretty much perfect. I've taken your advise and renamed the fields so theres no gaps :-) The only thing i've got now if when there is just a company name - there is a ',' before it.. I tried having a little play around, trying to follow what you did - but I'm not getting any closer..

  9. #9
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The only thing i've got now if when there is just a company name - there is a ',' before it.. I tried having a little play around, trying to follow what you did - but I'm not getting any closer..
    I saw that, but.... well I didn't want to fix it because you might think I was a Nerd.

    Well, I guess I just proved it........

    Code:
    ContactName2: nz([name1],"") & IIf(IsNull([name1]),"",IIf(IsNull([name2])," "," & ")) & nz([name2],"") & IIf(IsNull([name2]),""," ") & nz([Surname],"") & IIf(IsNull([companyname]),"",IIf(IsNull([Name1]) And IsNull([name2]) And IsNull([Surname]),"",", ")) & Nz([companyname],"")

  10. #10
    annaisakiwi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    8
    Quote Originally Posted by ssanfu View Post
    I saw that, but.... well I didn't want to fix it because you might think I was a Nerd.

    Well, I guess I just proved it........

    Code:
    ContactName2: nz([name1],"") & IIf(IsNull([name1]),"",IIf(IsNull([name2])," "," & ")) & nz([name2],"") & IIf(IsNull([name2]),""," ") & nz([Surname],"") & IIf(IsNull([companyname]),"",IIf(IsNull([Name1]) And IsNull([name2]) And IsNull([Surname]),"",", ")) & Nz([companyname],"")

    LOL nerd! not at all... a big help definately!!! thanks again!!!

  11. #11
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You're too kind...

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

Similar Threads

  1. Combining fields on a report
    By Alaska1 in forum Access
    Replies: 1
    Last Post: 12-15-2010, 12:14 PM
  2. Combining two fields in Access
    By jo15765 in forum Programming
    Replies: 18
    Last Post: 11-20-2010, 07:23 PM
  3. Combining fields
    By cotri in forum Forms
    Replies: 2
    Last Post: 01-18-2010, 12:06 PM
  4. combining fields into a single list
    By rich in forum Queries
    Replies: 4
    Last Post: 02-23-2009, 06:41 AM
  5. Replies: 1
    Last Post: 06-03-2006, 05:02 PM

Tags for this Thread

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