Results 1 to 6 of 6
  1. #1
    Special_Egg is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    3

    Multiple "OR" functions

    Hello forum,
    I'm attempting to write a query that will return a value based on letters parsed out from a unique identifier. So, if the identifier contains the letters xr, then return the value X-Ray or if the identifier contains the letters mr, then return the value MRI, or if the identifier contains the letters ir, then return the value Interventional Radiology, and so on. I know this will work because I did it years ago, I just can't remember the syntax.

    UNIT: IIf([CleanStudyMoves].[Identifier] Like "*XR*",'X-Ray') Or IIf([CleanStudyMoves].[Identifier] Like "*IR*",'Interventional Radiology')

    It returns a value of -1 when I run it. Any help is appreciated.

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    dont use OR. Do a Search for Nested IIF's.


  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Nested IIf()'s or a Switch() function.

    How many 'so on'? AFAIK, nested IIf() is limited to 7 levels.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Special_Egg is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    3
    The nested IIF's resolved my problem. The code below works great. As you can see, nested IIF's are not limited to 7 levels.

    MODALITY: IIf([CleanStudyMoves].[Identifier] Like "*XR*",'X-Ray',IIf([CleanStudyMoves].[Identifier] Like "*IR*",'Interventional Radiology',IIf([CleanStudyMoves].[Identifier] Like "*US*",'Ultra Sound',IIf([CleanStudyMoves].[Identifier] Like "*CT*",'Computerized Topography',IIf([CleanStudyMoves].[Identifier] Like "*OR*",'Orthopedics',IIf([CleanStudyMoves].[Identifier] Like "*MA*",'Mammography',IIf([CleanStudyMoves].[Identifier] Like "*MR*",'MRI',IIf([CleanStudyMoves].[Identifier] Like "*NM*",'Nuc Med',IIf([CleanStudyMoves].[Identifier] Like "*BP*",'DEXA',Null)))))))))

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Okay, maybe confused with nested subforms.

    Might explore the Switch() function. I think it would simplify the expression.

    MODALITY: Switch([Identifier] Like "*XR*",'X-Ray', [Identifier] Like "*IR*",'Interventional Radiology', [Identifier] Like "*US*",'Ultra Sound', [Identifier] Like "*CT*",'Computerized Topography', [Identifier] Like "*OR*",'Orthopedics', [Identifier] Like "*MA*",'Mammography', [Identifier] Like "*MR*",'MRI', [Identifier] Like "*NM*",'Nuc Med', [Identifier] Like "*BP*",'DEXA', True,"N/A")

    Should "Topography" be "Tomography"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Special_Egg is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    3
    Yes, switch simplified the expression. Thank you very much for your help June. And thanks for catching my typo. LOL

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

Similar Threads

  1. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  2. Replies: 1
    Last Post: 05-10-2012, 11:56 AM
  3. Custum Functions in Query "WHERE" Clause
    By trb5016 in forum Queries
    Replies: 1
    Last Post: 02-15-2012, 03:30 PM
  4. "And" stops functions from working
    By JimmD43 in forum Programming
    Replies: 5
    Last Post: 03-19-2011, 11:10 AM
  5. Replies: 1
    Last Post: 12-11-2008, 01:28 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