Results 1 to 3 of 3
  1. #1
    dskysmine is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    14

    How To Create A Field Name Dependent On Multiple Fields


    Hello all,

    I have a Table with multiple fields, and I am trying to create a single field that is the concatenation of fields that have data on them.
    Check Attachment how the table is.
    Click image for larger version. 

Name:	Example Table.png 
Views:	12 
Size:	6.9 KB 
ID:	13436
    I know that Field A is always present, but in the others there might be data or it might be "NA".
    What I want to create is a Query that returns in one field the concatenation of the fields that have data.
    So for Record 1 it would be: A1_B2_D1_E1
    For record 2: A2_C2_D2
    For record 3: A3_B3_C3_D3_F3

    I tried doing this using IIF and Switch in Access, but it doesn't work.
    This kind of logic doesn't work in Access:
    Field1: [A] &"_"& IIF([B]="NA","",[B]) & ...
    And with nested IIFs (from [A] to [F]) if there is a value in F it will return for record 3: A3_B3_C3_D3_NA_F3

    Does anybody know how to do this?
    Thank you very much.
    Kind regards.

    PS: My access is 2007.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I think you were on the right track. Making a minor tweak to your previous attempt should work:
    Code:
    Field1: [A] & IIf([B]="NA","","_" & [B]) & IIf([C]="NA","","_" & [C]) & IIf([D]="NA","","_" & [D]) & IIf([E]="NA","","_" & [E]) & IIf([F]="NA","","_" & [F])

  3. #3
    dskysmine is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    14
    You are right. It worked great. Thank you very much!

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

Similar Threads

  1. Create report that is True/false dependent
    By nomadinlondon in forum Reports
    Replies: 1
    Last Post: 03-19-2013, 11:24 AM
  2. (Again) dependent fields,
    By jamal numan in forum Access
    Replies: 12
    Last Post: 10-25-2012, 07:17 AM
  3. Replies: 4
    Last Post: 07-13-2012, 12:47 PM
  4. Replies: 1
    Last Post: 03-27-2012, 01:30 PM
  5. Replies: 0
    Last Post: 12-16-2009, 09:28 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