Results 1 to 10 of 10
  1. #1
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159

    Combine two fields, Null fields involved

    Title may not make much sense, so if you have come this far then stick with me.



    I want to combine two fields for a form and probably on a couple of reports as well. I want a comma to show if both fields contain a value, however, if only one of the fields has a value and the other does not, then I do not want a comma.

    For example, there are college athletes that have played some international ball before playing collegiality.

    Lets say I have a field called 'College' and another as 'International Club.'

    Obviously, I know I can display this as Team: [College] & ", " & [International Club]. However, by doing this, for any player with just International experience and no College, their field will display as ", International Club."

    To sum things up, I just want a comma to show when it is necessary.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The "+" instead of the "&" will *almost* do what you want. The "&" is the accepted concatenation character but the plus sign "+" will propagate the null field and the "&" will not. You may need to make this a two stage operation because you cannot just replace the "&" with a "+" since you do not know which field may be Null. If you replace all of the "&" with "+" then any null will wipe out any valid entry. IHTH's.

  3. #3
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Quote Originally Posted by RuralGuy View Post
    The "+" instead of the "&" will *almost* do what you want. The "&" is the accepted concatenation character but the plus sign "+" will propagate the null field and the "&" will not. You may need to make this a two stage operation because you cannot just replace the "&" with a "+" since you do not know which field may be Null. If you replace all of the "&" with "+" then any null will wipe out any valid entry. IHTH's.

    Yeah, I switched the & to a + earlier, and then any merged label that didn't contain a value in each field was just completely wiped out and was empty. Only the label that had both fields would display.

  4. #4
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    I don't quite understand your two stage operation statement.

  5. #5
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Damn, that was easy.

    I changed over to this Team: [College] & ", " + [International Club]

    As simple as that was, this is pretty freaking awesome.

  6. #6
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Quote Originally Posted by yes sir View Post
    Damn, that was easy.

    I changed over to this Team: [College] & ", " + [International Club]

    As simple as that was, this is pretty freaking awesome.


    DENIED

    Now if there is a only an International Club it shows as ", International Club"

    I got a little too excited. Whoops. Back to the drawing board.

  7. #7
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    I have tried using an expression like this:

    =IIf(IsNull([College]) or [College]="","",[College])
    & IIf(IsNull([International Club]) or [International Club]="","",(", " & [International Club]))

    However, if there is an instance where a player has an International Club and NOT College, then the comma still shows. ", International Club"

    There really seems to be no way around this.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try: AIR CODE
    Code:
    =IIf(Len([College]) And Len([International Club]), _
          [College] & "," & [International Club], _
          IIf(Len([College]), _
             [College], _
             IIf(Len([International Club]), _
                [International Club], "")))

  9. #9
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Per ajetrumpet:

    Team: IIf([School] Is Null,IIf([International Club] Is Null,"",[International Club]),IIf([International Club] Is Null,[School],[School] & ", " & [International Club]))

    Works just the way I want.

    Returns the three possible values the way I want, "School" "International Club" "School, International Club"

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Thanks for posting back with your success.

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

Similar Threads

  1. Combine First and Last name fields for Report
    By yes sir in forum Reports
    Replies: 32
    Last Post: 08-31-2010, 07:31 PM
  2. Combine two unrelated tables with the same fields
    By lghovden06 in forum Queries
    Replies: 4
    Last Post: 07-27-2010, 03:36 PM
  3. Combine 2 Fields to make a hyperlink
    By ahightower in forum Forms
    Replies: 2
    Last Post: 06-30-2010, 08:59 PM
  4. Replies: 5
    Last Post: 03-20-2010, 08:30 AM
  5. Combine fields into one
    By cotri in forum Forms
    Replies: 2
    Last Post: 03-04-2010, 02:42 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