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

    Combining "and" & "or" iif statements

    Good evening, I have been struggling with creating a calculated field in a table. I am attempting to create a True/False field based on the following criteria.
    IIf([PNCName] Like "*L3*") and (IIf([TypeShipInstructionsID] =5 or [TypeShipInstructionsID] =6), True, False))

    I keep getting the error "The expression you entered has a function containing the wrong number of arguments. I am attempting to combine an "and" & "or" iif statement.


    Suggestions?

  2. #2
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    IMHO, you should NEVER put a calculated FIELD in a table. Tables are for STORING data. The calculation should be in a query.

    However, try this:
    Code:
    IIF(([PNCName] Like "*L3*") AND ([TypeShipInstructionsID] = 5 OR [TypeShipInstructionsID] = 6), True, False )

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    for something like this you do not need the iif function, just the formula

    [PNCName] Like "*L3*" AND ([TypeShipInstructionsID] = 5 OR [TypeShipInstructionsID] = 6)

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,175
    Quote Originally Posted by ssanfu View Post
    Iyou should NEVER put a calculated FIELD in a table. Tables are for STORING data. The calculation should be in a query.
    2 reasons to use calculated fields:
    * if you need to speed up searches on the field and have to put an index on it
    * If you need the field as a link field to another table (for example: for import)

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    2 reasons to use calculated fields:
    * if you need to speed up searches on the field and have to put an index on it
    * If you need the field as a link field to another table (for example: for import)
    you can't index a calculated field

  6. #6
    Join Date
    Apr 2017
    Posts
    1,776
    In case you really need to have calculated value in table, then instead of using formula use VBA script to save the calculated value!

    Of-course then you must have AfterUpdate events in all controls linked to fields used as sources in calculation, and those events must recalculate this value whenever any of sources is changed. And when you run some script to update any of those sources, this script must update the calculated value too. All this will be quite a headache - so use this option with caution!

  7. #7
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I've always gone with Allen Browne's site about Calculated Fields

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

Similar Threads

  1. Replies: 28
    Last Post: 03-23-2021, 11:02 AM
  2. Replies: 3
    Last Post: 10-30-2019, 09:37 PM
  3. Simple table relationships ("faces" to "spaces" to "chairs")
    By skydivetom in forum Database Design
    Replies: 36
    Last Post: 07-20-2019, 01:49 PM
  4. Replies: 12
    Last Post: 10-01-2018, 02:40 PM
  5. Replies: 1
    Last Post: 09-07-2015, 08:00 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