Results 1 to 5 of 5
  1. #1
    mdnikki is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    63

    Operand without an operator error

    I am trying to put this in a query.
    I don't see what I am missing here when I try to save this I am getting this error invalid syntax and the operand without an operator. Can someone see what I am missing.



    Delinquency Category: IIf([Days Overdue]<90,"Current",IIf([Days Overdue] Between 90 And 179,"3 to 6 Months",IIf([Days Overdue] Between 180 And 364,"6 to 12 Months",IIf([Days Overdue] Between 365 And 730,"1 to 2 Years",IIf([Days Overdue] Between 731 And 1094,"2 to 3 Years”, IIf([Days Overdue] Between 1095 And 1459,"2 to 3 Years”, IIf([Days Overdue] Between 1460 And 1825,"4 to 5 Years", "5 Years or More"))))))))



    I should say the original query had this and worked fine, I just added a few more categories and thats when it gave me the error

    Delinquency Category: IIf([Days Overdue]<90,"Current",IIf([Days Overdue] Between 90 And 179,"3 to 6 Months",IIf([Days Overdue] Between 180 And 364,"6 to 12 Months",IIf([Days Overdue] Between 365 And 730,"1 to 2 Years",IIf([Days Overdue] Between 731 And 1495,"2 to 3 Years","3 Years or More")))))

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    1. you really should not use multi nested IIFs. Its a pain to program, read and debug.
    instead, use a table with MIN, MAX values to pull the result
    or
    use a custom Function that does similar to the IIF but more readable and easier to program.
    Code:
    function getOverDueMsg(pvDays)
    select case true
        case pvDays<90
           getOverDueMsg= "Current"
        case pvDays>90 and pvDays <179
           getOverDueMsg= "3 to 6 Months"
    end function
    2. I dont think you can use BETWEEN in the IIf. This only works in query criteria, not here.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    ,IIf([Days Overdue] Between 731 And 1094,"2 to 3 Years, IIf([Days Overdue] Between 1095 And 1459,"2 to 3 Years, IIf([Days Overdue] Between 1460 And 1825,"4 to 5 Years",
    The problem is that the 2 closing double quotes (in red above) is not a standard double quote. If you delete the double quote, then retype the double quote, it should work.... at least it did for me.

    Also the text is wrong for the "Between 1095 And 1459" comparison.
    Look at this
    Code:
    Delinquency Category: 
    IIf([Days Overdue]<90,"Current",
    IIf([Days Overdue] Between 90 And 179,"3 to 6 Months",
    IIf([Days Overdue] Between 180 And 364,"6 to 12 Months",
    IIf([Days Overdue] Between 365 And 730,"1 to 2 Years",
    IIf([Days Overdue] Between 731 And 1094,"2 to 3 Years,   << -- fix the double quotes (in red)
    IIf([Days Overdue] Between 1095 And 1459,"2 to 3 Years,   << --should be "3 to 4 Years"  /fix the double quotes (in red)
    IIf([Days Overdue] Between 1460 And 1825,"4 to 5 Years", "5 Years or More")))))))      <<- should be 7 closing parns
    NOTE: Should never use spaces in object names....


    If you decide to go the way ranman suggested, the function would be
    Code:
    Function getOverDueMsg(pvDays As Long) As String
        Select Case True
            Case pvDays < 90
                getOverDueMsg = "Current"
            Case pvDays >= 90 And pvDays < 179
                getOverDueMsg = "3 to 6 Months"
            Case pvDays >= 180 And pvDays < 364
                getOverDueMsg = "6 to 12 Months"
            Case pvDays >= 365 And pvDays < 730
                getOverDueMsg = "1 to 2 Years"
            Case pvDays >= 731 And pvDays < 1094
                getOverDueMsg = "2 to 3 Years"
            Case pvDays >= 1095 And pvDays < 1459
                getOverDueMsg = "3 to 4 Years"
            Case pvDays >= 1460 And pvDays < 1825
                getOverDueMsg = "4 to 5 Years"
            Case pvDays >= 1826
                getOverDueMsg = "5 Years or More"
        End Select
    
    End Function
    To use it in a query:
    Code:
    DelinquencyCategory: getOverDueMsg([Days Overdue])

  4. #4
    mdnikki is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    63
    Thank you removing the quotes and replacing them worked. I appreciate your help.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Glad to help.

    Ready to mark this solved??

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

Similar Threads

  1. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  2. Operand without an operator error
    By Thompyt in forum Programming
    Replies: 3
    Last Post: 04-15-2015, 04:38 PM
  3. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  4. Operand without operator or
    By burrina in forum Queries
    Replies: 2
    Last Post: 12-31-2012, 06:14 PM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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