Results 1 to 7 of 7
  1. #1
    MSdove1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    3

    Query with IIF Function

    Hello all,

    I am somewhat of an access novice. I am trying to create a calculated field in a query using the IIF function. I am looking at a column with costs in it. In the query, I want the column title to be "Sponsored?" and if the value in the field is $0.00 I want it to return "No", otherwise "Yes". The name of the column I am pulling from is Sponsor Cost

    Here is what I attempted: Sponsored?: IIf([Sponsor Cost]="$0.00","No","Yes")



    I keep getting #Error when I run the query. Thoughts on what I am doing wrong?

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    If Sponsor cost is a number data type then it wants numbers from you - as in: If=0 then... They way you have it typed above is for text fields.

  3. #3
    MSdove1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    3
    The sponsor cost is a currency. So forgive my ignorance, but how would I re-write the function correctly for a currency?

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    What is the error? In the table as aytee111 suggests, what is the data type of [Sponsor Cost]? Does the value in that field have the $ in it?

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Yes, currency is a format (what it looks like, not how Access stores it in the table), not a data type.

  6. #6
    MSdove1 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    3
    Quote Originally Posted by Bulzie View Post
    What is the error? In the table as aytee111 suggests, what is the data type of [Sponsor Cost]? Does the value in that field have the $ in it?
    Yes, the value has the $ in it. Here is a snip of the column in question. So, I want to write a query such that any time the value in this column is $0.00, the result is "No" but if it is anything other than $0.00, the result is "Yes". Is that helpful in providing the information needed to help?
    Click image for larger version. 

Name:	access pic.PNG 
Views:	9 
Size:	106.1 KB 
ID:	28107

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by aytee111 View Post
    Yes, currency is a format (what it looks like, not how Access stores it in the table), not a data type.
    Actually it is also a data type.

    @MSDove, try:

    Sponsored?: IIf([Sponsor Cost]=0,"No","Yes")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2017, 11:31 AM
  2. Sum function within query
    By Vinagray@gmail.com in forum Reports
    Replies: 9
    Last Post: 10-14-2016, 04:23 PM
  3. Function won't run in a Query
    By Paul H in forum Programming
    Replies: 12
    Last Post: 07-08-2015, 12:16 PM
  4. VBA function query
    By Pacific1 in forum Programming
    Replies: 1
    Last Post: 12-04-2014, 01:19 PM
  5. Replies: 4
    Last Post: 11-19-2010, 07:21 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