Results 1 to 5 of 5
  1. #1
    swat is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    21

    query iif statement help

    Hello again all,

    Looking for help with my nested if statement, it works correctly for the "if true" and "then" parts. Here is what I have for a query field:

    Gas_Capacity: IIf(Year([Equip_Add_Rem_Log].[Date_Changed])>[year],IIf(([Equip_Add_Rem_Log].[Removal]=False),[Equipment].[Gas Capacity],"0"))


    My problem is, if there is no "year(...)" greater than "[year]" on the table, the query returns a blank field (is this a null). How do I get the query to recognize a "" as a false return on the first "if true"?

    Hmm, now that I think of it, it could possibly be an infinite return of falses if set up wrong. My head is spinning...any help would be greatly appreciated.



    Shawn

  2. #2
    swat is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    21
    I have also tried to leave it as a blank using the same iif statement, then creating another query with:
    1st query:
    Gas_CapacityAdded: Sum(IIf(Year([Equip_Add_Rem_Log].[Date_Changed])>[year],IIf(([Equip_Add_Rem_Log].[Removal]=False),[Equipment].[Gas Capacity],"0")))
    2nd Query:
    EquipAddedAfter: IIf([EquipAfterCurrent].[Gas_CapacityAdded]="","0",[EquipAfterCurrent].[Gas_CapacityAdded])

    But that returns an error in the field, no pop up though.

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    How about:

    Gas_Capacity: IIf(Year(Nz([Equip_Add_Rem_Log].[Date_Changed],0))>[year],IIf(([Equip_Add_Rem_Log].[Removal]=False),[Equipment].[Gas Capacity],0))

    By the way, I took the quotes off of the 0 at the end because I am assuming based on the field name that it is a NUMBER and not TEXT. But you can correct me if wrong.

  4. #4
    swat is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    21
    Thank you for the quick reply Bob. You were correct for the 0. The Nz statement didn't work, but now that I am reading up on it, it looks like it should work. I will keep reading about it and see what I can come up with. Thank you again.

  5. #5
    swat is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    21
    I think I got it to work, I used the nz in the second query and got it to work.

    EquipCapAddedAfter: Nz([EquipAfterCurrent].[Gas_CapacityAdded],0)

    I just hate having so many queries to get to the end, but if it works then that is what matters I guess.

    Thank you again for your help sir.

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

Similar Threads

  1. Query/IiF statement
    By peacepower in forum Queries
    Replies: 1
    Last Post: 08-23-2011, 04:05 PM
  2. Help fix SQL Statement for query
    By Budro49 in forum Queries
    Replies: 12
    Last Post: 06-21-2011, 02:26 PM
  3. Help with Query iif statement for newb.
    By edmcgee in forum Queries
    Replies: 5
    Last Post: 01-25-2011, 10:27 AM
  4. I need help writing a query statement
    By dking in forum Queries
    Replies: 1
    Last Post: 02-25-2009, 09:43 AM
  5. If then statement in query
    By ronnie4 in forum Queries
    Replies: 1
    Last Post: 01-20-2009, 10:49 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