Results 1 to 7 of 7
  1. #1
    DrDefpoints is offline Novice
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    3

    IIF Statement Returning #Error

    I haven't use Access for a very long time so I may just be missing something simple. The problem is as follows:



    I'm using the following IFF statement in a Query:

    Expr1: IIf([ODG-Bill]![Date-PO-Rcvd]="",[ODG-Bill]![Fee1],"")

    So what I'm going for is to have it return the fee amount listed in the Fee field if the PO Rcvd Date is Blank.

    What I'm getting is a blank for False (This i want I want) and "#Error" for True.

    What I'm I missing

    Thanks
    Jeff

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    is this in a form field?? form fields are denoted by the field names enclosed in []. Nothing else required.

    what is ODG-Bill??

  3. #3
    DrDefpoints is offline Novice
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    3
    [ODG-Bill] is the Table name and [Date-PO-Rcvd] is the field name it that table. I'm entering the Expertion into the Field box of a new Query. I used the expression builder to build this and it inserted the [ODG-Bill]![Date-PO-Rcvd] when I selected it.

    Removing the [ODG-Bill]! from the equation did not help. I still get the #error in the Query for all True records
    Last edited by DrDefpoints; 05-25-2011 at 05:16 PM. Reason: Adam Suggested Field Name Only

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    i've seen this done a million times. some claim it works, others claim not.

    use DLOOKUP instead, in your control source. that doesn't provide #ERROR, ever.

    I cant remember the return value if it doesnt find an entry, but I dont think it's #error.

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Quote Originally Posted by DrDefpoints View Post
    [ODG-Bill] is the Table name and [Date-PO-Rcvd] is the field name it that table. I'm entering the Expertion into the Field box of a new Query. I used the expression builder to build this and it inserted the [ODG-Bill]![Date-PO-Rcvd] when I selected it.

    Removing the [ODG-Bill]! from the equation did not help. I still get the #error in the Query for all True records
    If Date-PO-Rcvd is a Date data type, I don't think a missing entry will be a zero length string (""). I think you should be checking for
    IsNull([Date-PO-Rcvd]). And, if Fees is a numeric value, then false would return 0 ( in my view)

    MyFees: IIf(IsNull([ODG-Bill]![Date-PO-Rcvd]),[ODG-Bill]![Fee1],0)

    But, more important is the meaning of the iif statement.

    To me you are saying:
    If there is no [Date-PO-Rcvd], then use [ODG-Bill]![Fee1]
    which seems a little confusing. Perhaps you could explain what you are trying to accomplish. It could be you have just used the default Expr1 that Access assigns, and not something like MyFees: or similar.

    As Adam pointed out
    What is ODG-Bill?
    there are several naming approaches that identify Tables etc, and don't use special characters "-".
    Following a naming convention can save a lot of headaches and reduce confusion if someone, other than you, has to read/modify the code.

  6. #6
    DrDefpoints is offline Novice
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    3
    Quote Originally Posted by orange View Post
    If Date-PO-Rcvd is a Date data type, I don't think a missing entry will be a zero length string (""). I think you should be checking for
    IsNull([Date-PO-Rcvd]). And, if Fees is a numeric value, then false would return 0 ( in my view)

    MyFees: IIf(IsNull([ODG-Bill]![Date-PO-Rcvd]),[ODG-Bill]![Fee1],0)
    This worked perfect Thanks... I'll look into naming conventions

    Quote Originally Posted by orange View Post
    To me you are saying:
    If there is no [Date-PO-Rcvd], then use [ODG-Bill]![Fee1]
    Yes you are exactly right. I am trying to generate a report that has two columns one column is The fees we have received a PO (Purchase Order) for and one is for Fees we have not Received a PO for. When we receive a PO a date is entered, hence I figured an Expression to check whether there was a date or not would accomplish my task. If there is a better way I'm all ears. Next I'd need to check VS two different fields and was just going to use a Nested IIF statement.

    Thanks Again

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Glad to help.
    Good luck with the naming, it is important.

    Here's a link you might find interesting - even the first few topics.
    http://www.rogersaccesslibrary.com/forum/topic238.html

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

Similar Threads

  1. Replies: 8
    Last Post: 12-04-2010, 07:53 PM
  2. IIf Statement Syntax Error
    By shexe in forum Queries
    Replies: 2
    Last Post: 10-06-2010, 08:35 AM
  3. compile error: expected end of statement
    By RedGoneWILD in forum Programming
    Replies: 5
    Last Post: 07-29-2010, 10:12 AM
  4. Replies: 2
    Last Post: 12-03-2009, 05:06 PM
  5. Syntax Error In Insert Into Statement
    By frankvfox in forum Queries
    Replies: 1
    Last Post: 09-09-2008, 12:35 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