Results 1 to 12 of 12
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Combining two fields Help


    I have a query that is combining two fields:
    Code:
    Full Name: [FirstName] & " " & [LastName]
    Sometimes last name may be null, how can I set the query to only display LastName if it is not null?

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Is the issue the extra space at the end if there is no last name?
    You could use and IF statement along with ISNULL, or something as simple as this:
    Code:
    Full Name: Trim([FirstName] & " " & [LastName])

  3. #3
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    That fixed problem 1. Thank you.

    My next problem is I am running this code:
    Code:
    Address: Replace([Address1] & [Address2] & [Address3], "|", ",")
    The issue I have here is 2 fold...1) There is always a space between address1 and address2 I would like it to just read address1, address2, address3. Then if there is no address3 not place a comma after address2

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Can you post a few examples of what can be in Address1, Address2, and Address3 and what your final result should look like?

  5. #5
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Desired outcome:
    1100 N Main Street, Office 12, Suite 110 (if all 3 fields have data)
    1100 N Main Street, Office 12 (if only 2 fields have data)
    1100 N Main Street (if only one field has data)

    And that is also the data that will be in the fields. Does that help clarify?

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    How about:

    Code:
    Address: [Address1] & IIF(LEN([Address2])>0,", " & [Address2],"") & IIF(LEN([Address3])>0,", " & [Address3],"")

  7. #7
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    That is working with the exception of needing a comma between Address1 & Address2 if address2 exists. At least on my end.
    So...
    1100 N Main Street, Office 12
    Or Read
    1100 N Main Street

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    That is working with the exception of needing a comma between Address1 & Address2 if address2 exists. At least on my end.
    Its there. Maybe you didn't copy my formula completely.
    Take a look again at my previous post, and notice in each IIF statement a comma and space that appears before it returns the appropriate Address field.

  9. #9
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Oh you are correct, I apologize for my oversight. and thank you greatly for the assistance.

  10. #10
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Glad to help!

  11. #11
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    I marked this as solved as it was working then, but I must have changed something to not have it working now

    This is the syntax
    Total: Replace([FirstOffer] & IIf(Len([Offer2])>0,", " & [Offer2],""),"|",",")

    And it tells me undefined function 'Replace' in expression???

  12. #12
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Not sure. Your formula works for me, exactly as you have written it.

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

Similar Threads

  1. Combining Redundant Fields
    By igendreau in forum Queries
    Replies: 3
    Last Post: 07-19-2011, 11:35 AM
  2. Combining Table Fields
    By jsimard in forum Access
    Replies: 2
    Last Post: 02-22-2011, 04:05 PM
  3. Combining fields - iif??
    By annaisakiwi in forum Queries
    Replies: 10
    Last Post: 12-22-2010, 07:49 PM
  4. Combining two fields in Access
    By jo15765 in forum Programming
    Replies: 18
    Last Post: 11-20-2010, 07:23 PM
  5. Combining fields
    By cotri in forum Forms
    Replies: 2
    Last Post: 01-18-2010, 12:06 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