Results 1 to 4 of 4
  1. #1
    Macallan60 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2010
    Posts
    51

    Switch Function

    Hello,



    I need some help with a switch function. I have heard this was better to use than nested IIf functions. Attached is a example database. My switch function in the a new field named "Loc" in the selWIP_Download query. It works great. However, for all the records that are null in my query, I want to use the value that is in the "Status" field. Any help is appreciated.

    I hope this makes sense.

    Thank youExample.accdb

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Advise not to use spaces in naming convention.

    Just add one more condition in the Switch at the end: True, [Status]. Any record not matching the other conditions will pull from Status

    One record (Status Flag 30) does not have any data.
    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.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Macallan60 View Post
    However, for all the records that are null in my query, I want to use the value that is in the "Status" field. Any help is appreciated.
    Whaaaat?
    Where the whole record is Null? OR specific Fields are NULL? Or one specific Field is NULL?

    Something like this?

    In your query, I moved the [Checker ID] column to be in the same place as in the table to make it easier to compare the results between the table and the 2 queries.

    I guessed that if [Checker ID] is NULL, you wanted to see the value from [Status] in the [Loc} column.
    So I created another query (Query1) using this SQL:
    Code:
    SELECT tblWIP_Download.[Status Flag], tblWIP_Download.[Checker ID], Switch([Status Flag] In ('10') And [Checker ID] Is Not Null,"Embroidered, Not Complete", [Status Flag] In ('10') And [Checker ID] Is Null,"Not Started", [Status Flag] In ('20','25','60'),"Complete", [Status Flag] In ('00','05'),"Not Started",
     [Checker ID] Is Null,[Status]) AS Loc FROM tblWIP_Download;
    Is this close???
    Attached Thumbnails Attached Thumbnails Results1.png  

  4. #4
    Macallan60 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2010
    Posts
    51
    Thank you both for your suggestions. Works perfectly!

    June7 - I'll get to work on removing those spaces. Thanks again.

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

Similar Threads

  1. SWITCH Function SYNTAX
    By Elio in forum Queries
    Replies: 1
    Last Post: 05-15-2018, 03:27 PM
  2. Replies: 12
    Last Post: 05-14-2017, 10:11 AM
  3. Alernative to SWITCH function???
    By elender in forum Queries
    Replies: 5
    Last Post: 02-09-2017, 06:54 PM
  4. Using SQL switch function MS Access
    By sandlucky in forum Queries
    Replies: 18
    Last Post: 03-31-2011, 08:49 AM
  5. Select Query in Switch Function
    By sandlucky in forum Queries
    Replies: 0
    Last Post: 03-30-2011, 04:54 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