IIF vs RecordSet issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wquatan
    New Member
    • Oct 2007
    • 48

    #1

    IIF vs RecordSet issue

    Let's assume we have :

    - a recordset (rs) from a query returning no records
    - a wrkField containing "A"

    The following statement
    Code:
    wrkTarget = iif(rs.EOF, "NO", rs.[Field])
    works correctly, wrkTarget = "NO" in the example

    The statement
    Code:
    wrkTarget = iif(rs.EOF, "NO", iif(wrkField = "A", "YES", rs.[Field]))
    gives an error "No Current record" dispite the fact it should never get to rs.[Field]

    Does someone knows what's happening and how to bypass (I know IF ... THEN ... ELSE, but want to keep going with IIF)

    Thanks
    Last edited by NeoPa; Nov 25 '10, 10:58 PM. Reason: Added CODE tags
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Originally posted by WQuatan
    WQuatan:
    dispite the fact it should never get to rs.[Field]
    That statement is incorrect. It is behaving exactly as the documentation says it does. All parameters are evaluated before the call to the IIf() function is processed. They must be - to pass the values as parameters. Essentially, the error occurs before IIf() even starts to execute.

    Does that help?

    Comment

    Working...