Results 1 to 3 of 3
  1. #1
    sarahG is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    1

    Exclamation Error with writing IIF functions using expression builder.

    Hello,


    I am having issues with two expressions I am building for a query and not sure what the problem is. For both of the following, I get a invalid syntax error when I run them. Also, for #2 I am not sure how to sort the query correctly as it asks.

    1. Add an expression to display Freshman, Sophomore, Junior, or Senior for the correspondingClass codes FR, SO, JR, and SR. Use a nested IIF function.

    Code:
    IIf([Students]![Class]="FR,"Freshman",(IIf([Students]![Class]="SO","Sophmore",(IIf([Students]![Class]="JR","Junior",(IIf([Students]![Class]="SR","Senior")))))))
    2. Add another expression to display 1, 2, 3, or 4 for the corresponding Class codes FR, SO, JR, and SR. Sort the query on this expression so that the data will display in order of FR, SO, JR, then SR.

    Code:
    IIf([Students]![Class]="FR,"1",(IIf([Students]![Class]="SO","2",(IIf([Students]![Class]="JR","3",(IIf([Students]![Class]="SR","4")))))))
    I am using Access 2016 on a Windows 10 virtual machine on my Mac.
    Last edited by sarahG; 04-03-2020 at 04:29 PM. Reason: added version info

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Simplify this to
    Code:
    IIf(Students.Class="FR,"Freshman",IIf(Students.Class="SO","Sophmore",IIf(Students.Class="JR","Junior",IIf(Students.Class="SR","Senior"))))
    Or...
    Code:
    IIf(Students.Class="FR,"Freshman",IIf(Students.Class="SO","Sophmore",IIf(Students.Class="JR","Junior","Senior")))
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    For sort numbers, similar expression:

    IIf(Students.Class="FR",1,IIf(Students.Class="SO", 2,IIf(Students.Class="JR",3,4)))

    or

    Switch([Class]="FR",1, [Class]="SO",2, [Class]="JR",3, [Class]="SR",4)

    Or build a table for these attributes and include in query.
    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.

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

Similar Threads

  1. Replies: 1
    Last Post: 05-15-2018, 09:46 AM
  2. Replies: 4
    Last Post: 05-03-2016, 01:51 PM
  3. Replies: 1
    Last Post: 04-24-2013, 03:47 PM
  4. Expression builder error, circular reference
    By cowboy in forum Programming
    Replies: 3
    Last Post: 07-15-2010, 12:55 PM
  5. Writing Access functions
    By new2access123 in forum Programming
    Replies: 5
    Last Post: 02-06-2010, 10:47 PM

Tags for this 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
  •  
Other Forums: Microsoft Office Forums