If, then, else statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brynne
    New Member
    • Mar 2007
    • 13

    If, then, else statements

    Can someone give some advice? I am not big on VB scripts, so am trying to write an expression in an update query that is designed to populate a field which I will use as the email first letter. If the rank is SC then the prefix is "s", if the rank is "Admin" etc through to "SRO2 then the prefix is "c" otherwise the rank is a police officer and the prefix is "p". The letters s or c or p are entered into the field indicated in the query.

    The expression reads

    IIf([Workers]![Rank]="SC","s",II f([Workers]![Rank]="ADMIN" Or "AGENCY" Or "ANALYST" Or "CIV" Or "PHOTOG" Or "SCENE EX" Or "OTHER" Or "CIV SUPV" Or "Cadet" Or "Comms" Or "PCSO" Or "TraffW" Or "SRO","c"," p"))

    but it doesn't want to work.

    Could someone either tell me what is wrong with the expression, or show me a VB alternative that I can use to update all records?

    Many thanks,

    B
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The problem is with [Workers]![Rank]="ADMIN" Or "AGENCY" Or "ANALYST" and so on.

    You have to use either [Workers]![Rank] In("ADMIN", "AGENCY", "ANALYST") or [Workers]![Rank] = "ADMIN" Or [Workers]![Rank] = "AGENCY" and so on.

    Comment

    • brynne
      New Member
      • Mar 2007
      • 13

      #3
      It worked! Had tried In("Etc") before but the syntax was wrong. A million thanks.

      B

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Originally posted by brynne
        It worked! Had tried In("Etc") before but the syntax was wrong. A million thanks.

        B
        Not a problem.

        Comment

        Working...