Results 1 to 7 of 7
  1. #1
    newpete is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Posts
    4

    Question Expression Error

    What is wrong with this expression please



    =IIf(IsNull([Members Data]![His First Name]),Trim([Members Data]![Her First name]) & ' ' & Trim([Members Data]![Surname]),IIf(IsNull([Members Data]![Her First Name]),Trim([Members Data]![His First Name]) & ' ' & Trim([Members Data]![Surname]),Trim([Members Data]![His First name]) & ' ' & "&" & ' ' & Trim([Members Data]![Her First Name]) & ' ' & Trim([Members Data]![Surname])))

    It looks at 2 fields in a table' His First Name' and 'Her First Name' if either is empty it gives the other and adds a 'Surname'. If neither is empty (Null) it ouputs both names and surname. Doesn't work. Outputs #name?.
    I am new to this and am using 2013 on a windows 8 machine. What am i not seeing?
    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Try:

    =Trim([His First Name] & IIf(IsNull([Her First Name]), "", IIf(Not IsNull([His First Name]), " and ", "")) & [Her First Name])) & " " & [Members Data]![Surname])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    newpete is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Posts
    4
    Quote Originally Posted by June7 View Post
    Try:

    =Trim([His First Name] & IIf(IsNull([Her First Name]), "", IIf(Not IsNull([His First Name]), " and ", "")) & [Her First Name])) & " " & [Members Data]![Surname])
    Thank you June, I appreciate the prompt reply and the neatness compared to my effort. Unfortunately I make it 2 too many closing parenthesis but I don't know which ones. This is the first time I have tried this. I'm ure you will know very rapidly.
    Pete.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    =Trim([His First Name] & IIf(IsNull([Her First Name]), "", IIf(Not IsNull([His First Name]), " and ", "")) & [Her First Name] & " " & [Members Data]![Surname])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    newpete is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Posts
    4
    Hi June,
    Just got back to this. Unfortunately still same result #Name ?. Am I putting it in the right place. Data>control source of a report. This is just the 1st piece of information for this report , they were entered from an old excel list and edited and full of rubbish and needs expanding. Table and associated form are oK.
    Pet

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Report does not have ControlSource, textbox has ControlSource, report has RecordSource.

    Expression goes in textbox ControlSource or on the Field row of query.

    #NAME means Access can't find field referenced in expression. I forgot to remove a table reference prefix. Maybe that will make difference.

    =Trim([His First Name] & IIf(IsNull([Her First Name]), "", IIf(Not IsNull([His First Name]), " and ", "")) & [Her First Name] & " " & [Surname])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    newpete is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Posts
    4
    Thanks June.
    removed the table reference, still didn't work but found I had not put Members data as the record source in the report, so it then worked.

    You have already taught me a lot, but am sure I will be back

    Pete

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

Similar Threads

  1. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  2. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  3. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Replies: 1
    Last Post: 05-11-2012, 10:59 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