+ Reply to Thread
Results 1 to 5 of 5

Thread: Label Expression to not label if...

  1. #1
    Donovan Cameron

    Join Date
    Aug 2010
    Posts
    477
    Points
    40
    Answers Provided
    3


    0

    Default Label Expression to not label if...

    I am wondering how to get my label expression to not label a field if certain other fields are found.
    Below is my expression.

    Code:
    Function FindLabel ( [LTSA_LOT] , [LTSA_BLOCK] , [LTSA_PA4] , [LTSA_PLAN] , [LAND_AC6] )
     if ( Len ([LTSA_LOT]) <> 0) then 
      str1 = [LTSA_LOT] & " - "
     end if
     if ( Len ( [LTSA_BLOCK] )  <> 0) then
      str2 =  [LTSA_BLOCK] & " - "
     end if
     if ( Len ( [LTSA_PA4] )  <> 0) then
      str3 =  [LTSA_PA4] & " - "
     end if
     if ( Len( [LTSA_PLAN] ) <> 0) then
      str4 =  [LTSA_PLAN]
    end if
     if ( Len( [LAND_AC6] ) <> 0) then
      str5 =  [LAND_AC6]
    end if
     FindLabel = str1 & str2 & str3 & str4 & VBNewLine & str5
    End Function

    I would like the label to not label Str5, if labels are found for str1-4.

    Appreciate your time to help me with this.
    Last edited by SaultDon; 09-29-2010 at 01:12 PM.


  2. #2
    Ken Buja

    Join Date
    Jan 2010
    Posts
    1,212
    Points
    874
    Answers Provided
    151


    1

    Default Re: Label Expression to not label if...

    Here are two ways of looking at it. If you want to add the attribute for LAND_AC6 only when none of the other fields have any attributes, then use this.

    Code:
    Function FindLabel ( [LTSA_LOT] , [LTSA_BLOCK] , [LTSA_PA4] , [LTSA_PLAN] , [LAND_AC6] )
    
       if ( Len ([LTSA_LOT]) <> 0) then 
        str = [LTSA_LOT] & " - "
      end if
      if ( Len ( [LTSA_BLOCK] )  <> 0) then
          str = str + [LTSA_BLOCK] & " - "
      end if
      if ( Len ( [LTSA_PA4] )  <> 0) then
             str = str +  [LTSA_PA4] & " - "
        end if
        if ( Len( [LTSA_PLAN] ) <> 0) then
        str = str +   [LTSA_PLAN]
      end if
        if ( Len( [LAND_AC6] ) <> 0) then
        str1 =  [LAND_AC6]
       end if
    
      if (Len(str) > 0) then
        FindLabel = str
      else
        FindLabel = str1
      end if
    
     End Function
    If you want to add the attribute for LAND_AC6 if one or more of the other fields don't have any attributes, then this should work
    Code:
    Function FindLabel ( [LTSA_LOT] , [LTSA_BLOCK] , [LTSA_PA4] , [LTSA_PLAN] , [LAND_AC6] )
    
      dim found
      found = True
    
       if ( Len ([LTSA_LOT]) <> 0) then 
         str = [LTSA_LOT] & " - "
      else
          found = False
       end if
      if ( Len ( [LTSA_BLOCK] )  <> 0) then
           str = str + [LTSA_BLOCK] & " - "
      else
          found = False
      end if
      if ( Len ( [LTSA_PA4] )  <> 0) then
              str = str +  [LTSA_PA4] & " - "
      else
           found = False
        end if
        if ( Len( [LTSA_PLAN] ) <> 0) then
        str = str +   [LTSA_PLAN]
      else
           found = False
      end if
        if ( Len( [LAND_AC6] ) <> 0) then
        str1 =  [LAND_AC6]
       end if
    
      if found then
        FindLabel = str
      else
        FindLabel = str & vbNewLine & str1
      end if
    End Function
    Ken Buja
    Silver Spring, MD

  3. #3
    Donovan Cameron

    Join Date
    Aug 2010
    Posts
    477
    Points
    40
    Answers Provided
    3


    0

    Default Re: Label Expression to not label if...

    Perfect, thanks Ken,

    never thought of the Found=False parameter or setting desired labels to one str!


  4. #4

    Join Date
    Jul 2011
    Posts
    1
    Points
    0
    Answers Provided
    0


    0

    Default Re: Label Expression to not label if...

    I'm having some trouble. I have two fields that I want to label because on some rows, the data is different. What would the expression be if I wanted to label both fields but tell it not to label second field if values are the same? Thanks in advance!

  5. 07-14-2011 02:07 PM


  6. #5
    Donovan Cameron

    Join Date
    Aug 2010
    Posts
    477
    Points
    40
    Answers Provided
    3


    0

    Default Re: Label Expression to not label if...

    Quote Originally Posted by ballerjeff05 View Post
    What would the expression be if I wanted to label both fields but tell it not to label second field if values are the same?
    I went over a way how to compare two fields for matching values in a label expression over on the Cartotalk.

    There is another method mentioned in there, but using the StrComp function you would need to make a small change to the expression:

    Code:
    Function FindLabel ( [F1], [F2]  )
        intComp = StrComp( [F1], [F2], vbTextCompare )
          if intComp = -1 Then 
              FindLabel = [F1] & " - " & [F2] 
            Else
              FindLabel = [F1]
        End if
    End Function
    Results:
    Click image for larger version

Name:	label_2fields.png
Views:	77
Size:	15.8 KB
ID:	7784


+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts