Results 1 to 3 of 3
  1. #1
    tylerpickering is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    22

    Error with Query based on IIF statements

    When I try to use this statement, I get an error--any idea as to what the issue may be?

    Thanks!

    Lane Type: IFF(AND(ISNUMBER(VALUE(MID( [Orig NCS] ,4,1))),ISNUMBER(VALUE(MID( [Dest NCS] ,4,1)))),"ZTZ",IFF(ISNUMBER(VALUE(MID( [Orig NCS] ,4,1))),"ZTP",IFF(ISNUMBER(VALUE(MID( [Dest NCS] ,4,1))),"PTZ","PTP")))


    I copied it from excel and altered it as needed, not sure if there is something wrong with that...

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Access doesnt use AND that way. When 'IF' statements get this hairy...create a function. Much cleaner to read, and easily portable.
    Inthe query, call it with: calcVal([Orig NCS])

    Code:
    Public Function calcVal(ByVal pvIntv)
    Select Case Mid(pvIntv, 4, 1)
     Case "A"
        calcVal = "ZTZ"
     Case "B"
        calcVal = "ZTP"
     Case Else
        calcVal = "PTP"
    End Select
    End Function

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Access uses IIf(), Switch(), Choose() for conditional in-line expressions.

    IsNumeric() instead of IsNumber().

    Val() instead of Value().

    Val() results in a number entity (however, it will error on Null) and a text value will return 0.

    But you are extracting only 1 character from each field so don't see need for Val().

    IIf(IsNumeric(Mid([Orig NCS],4,1)) AND IsNumeric(Mid([Dest NCS],4,1)),"ZTZ", IIf(IsNumeric(Mid([Orig NCS],4,1)),"ZTP", IIf(IsNumeric(Mid([Dest NCS],4,1)),"PTZ", "PTP")))
    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. Need to customize error statements in form
    By mfmathes in forum Access
    Replies: 4
    Last Post: 04-01-2013, 07:26 AM
  2. Need to customize error statements in form
    By mfmathes in forum Programming
    Replies: 1
    Last Post: 03-29-2013, 07:38 AM
  3. Query iif statements
    By beckkks in forum Queries
    Replies: 1
    Last Post: 04-20-2012, 03:03 PM
  4. Nested If Statements Using Or (Logic Error)
    By IFA Stamford in forum Access
    Replies: 7
    Last Post: 12-30-2010, 08:53 AM
  5. Query for IIF statements
    By SpotoR1 in forum Queries
    Replies: 2
    Last Post: 08-26-2009, 06:57 AM

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