Results 1 to 3 of 3
  1. #1
    mlrucci is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    202

    IIf statement in query to return "Or" result

    Good afternoon, I am attempting to use an IIF statement to return 2 or 3 or 4 if a value is true. I have tried multiple variations without success. If the statement is false, it returns the correct value. The problem is if the statement is true, it will not return the true value. Here is my IIF statement



    IIf([Forms]![frmInvoiceDataPopUp]![txtSOWID1]=2 Or 3 ,2 Or 3 Or 4,[Forms]![frmInvoiceDataPopUp]![txtSOWID1])

    Any insight would be helpful!

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    If I walked up to you and said "2 or 3" what would your reaction be? That is what you're saying to Access. Each comparison operator must be qualified, as in (e.g. for x)
    IIf x=3 OR x=4 OR x=5... Your x is [Forms]![frmInvoiceDataPopUp]![txtSOWID1]
    However, you can't have "2 Or 3 Or 4" as the value part for when the test is true. Why would you make the 'if true' value arbitrary? The switch function might be better (assuming one can use it in a query) but I don't know as the expression seems a bit odd.
    Last edited by Micron; 06-09-2021 at 08:34 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    If you want to return the true value in case txtSOWID1 = 2 or 3 you need to specify this as:
    Code:
    
    
    Code:
    IIf([Forms]![frmInvoiceDataPopUp]![txtSOWID1]=2 Or [Forms]![frmInvoiceDataPopUp]![txtSOWID1] = 3 , ...
    

    Next, you need to specify 1 value that the function needs to return in case of true. You can't expect the computer to make a random choice.

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

Similar Threads

  1. Replies: 6
    Last Post: 04-06-2017, 07:10 AM
  2. Replies: 5
    Last Post: 03-22-2013, 01:11 PM
  3. Replies: 2
    Last Post: 11-14-2012, 04:47 PM
  4. Replies: 3
    Last Post: 06-29-2012, 08:54 AM
  5. Adding "Open" column to Query Result
    By premis in forum Queries
    Replies: 12
    Last Post: 05-30-2012, 03:47 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