Results 1 to 8 of 8
  1. #1
    mdnikki is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    63

    Joining two fields First name and spouse First name

    Good morning,

    I know how to join the fields but my issue is that some times there is no spouse first name.



    We are trying to personalize an eblast with first name fields so if there is a first name and a spouse first name I want them to appear but if there is no spouse first name I want on the first name to appear.

    Here is what I used.. .however when there is no spouse it shows Robert and

    FN: Trim$([AAA13 DM2]![CnBio_First_Name]) & " and " & Trim$([AAA13 DM2]![CnSpSpBio_First_Name])

    Any help is appreciated. I suppose I may need an iif statement in there somewhere.

    Thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Here's a short procedure to show the syntax
    Code:
    Sub testPlus()
        Dim n1(2, 1) As String
        n1(0, 0) = "John"
        n1(0, 1) = "Samantha"
        n1(1, 0) = "Tom"
        n1(1, 1) = ""   'Tom does not have a spouse
        n1(2, 0) = "Jeremiah"
        n1(2, 1) = "Danika"
    
        For i = 0 To 2
    '
    'The next line shows one syntax to do what you want
    '
            Debug.Print n1(i, 0) + IIf(Len(n1(i, 1) & "") = 0, "", " and " & n1(i, 1))
    '
            Next i
        End Sub
    'there is always a first name, so move it to output
    'The iif is saying
    if the length of the spouse name is 0, then add nothing to the output
    if the length of the spouse name is >0, then add the "and " & spouse name to the output

    Here is the output
    Code:
    John and Samantha
    Tom
    Jeremiah and Danika

  3. #3
    mdnikki is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    63
    I apologize, I am not that familiar with code. Is there a way to do this in the query as a concatenated field with and iif statement.

    Quote Originally Posted by orange View Post
    Here's a short procedure to show the syntax
    Code:
    Sub testPlus()
        Dim n1(2, 1) As String
        n1(0, 0) = "John"
        n1(0, 1) = "Samantha"
        n1(1, 0) = "Tom"
        n1(1, 1) = ""   'Tom does not have a spouse
        n1(2, 0) = "Jeremiah"
        n1(2, 1) = "Danika"
    
        For i = 0 To 2
    '
    'The next line shows one syntax to do what you want
    '
            Debug.Print n1(i, 0) + IIf(Len(n1(i, 1) & "") = 0, "", " and " & n1(i, 1))
    '
            Next i
        End Sub
    'there is always a first name, so move it to output
    'The iif is saying
    if the length of the spouse name is 0, then add nothing to the output
    if the length of the spouse name is >0, then add the "and " & spouse name to the output

    Here is the output
    Code:
    John and Samantha
    Tom
    Jeremiah and Danika

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Sure. Use this as a template

    n1(i, 0) + IIf(Len(n1(i, 1) & "") = 0, "", " and " & n1(i, 1))

    substitute
    Trim$([AAA13 DM2]![CnBio_First_Name])
    for n1(i,0)

    and
    Trim$([AAA13 DM2]![CnSpSpBio_First_Name]) for n1(i, 1)

    good luck

  5. #5
    mdnikki is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    63
    sal: Trim$([AAA13 DM2]![CnBio_First_Name])+IIf(Len(Trim$([AAA13 DM2]![CnSpSpBio_First_Name]) & "")=0,""," and " & Trim$([AAA13 DM2]![CnSpSpBio_First_Name]))

    Ok I think I did this correctly however for those with just a CNBio First name and no spouse I am getting a # Error message.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  7. #7
    mdnikki is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    63
    Its just a #Error in the field where the first name should be...just on those that have a Bio First name with no spouse. The concatenated field of first name and spouse name appears correctly.

    Thanks for you assistance and patience.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

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

Similar Threads

  1. Joining two Tables on two seperate Fields
    By Atlascycle in forum Queries
    Replies: 1
    Last Post: 01-23-2013, 09:01 AM
  2. Joining Memo Fields
    By Njliven in forum Queries
    Replies: 2
    Last Post: 12-28-2012, 12:34 PM
  3. Joining 2 tables on multiple fields
    By smoothlarryhughes in forum Queries
    Replies: 6
    Last Post: 12-13-2012, 10:40 AM
  4. Replies: 2
    Last Post: 05-29-2012, 07:13 PM
  5. Joining 2 fields in query to make one
    By robsworld78 in forum Queries
    Replies: 5
    Last Post: 07-11-2011, 12:06 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