Results 1 to 4 of 4
  1. #1
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92

    Switch Query for Yes/No

    Hello All!




    I am trying to use Switch in a query on a field that is a yes/no. The problem that I am having is that the query displays #Error when it is run. From what I can tell, that is due to it returning 0, but I can not fix it.

    Below are the two versions of what I have been trying to use.

    Code:
    Available: Switch([Availability]="true","Yes",[Availability]="false","")

    Code:
    Available: Switch([Availability]="yes","Yes",[Availability]="no","")


    I tried doing is null and is not null, but everything returns as not null.


    Any ideas?


    Thank you!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If the field is Yes/No type, don't put the parameters in quote marks.

    Regardless of any display formatting for a Yes/No field, the value is -1 or 0. True and False are Access/VBA constants. Constants do not go in quotes, otherwise you have the literal text true or false, not the value of the constant.
    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
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92
    June,


    Thank you for the help and for the explanation. That did the trick! I did not realize the literal vs constant issue, but it makes perfect sense now.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    BTW, should be same case for Yes and No.

    Ooops, maybe not, just tested.
    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.

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

Similar Threads

  1. Exporting A Query containing a SWITCH function - unable....
    By MissAran in forum Import/Export Data
    Replies: 2
    Last Post: 02-25-2014, 11:05 PM
  2. Replies: 3
    Last Post: 11-07-2013, 06:11 PM
  3. switch statement in a access query
    By Dominic in forum Access
    Replies: 1
    Last Post: 03-27-2013, 11:32 PM
  4. Select Query in Switch Function
    By sandlucky in forum Queries
    Replies: 0
    Last Post: 03-30-2011, 04:54 AM
  5. Switch function query to combine tables
    By sandlucky in forum Queries
    Replies: 2
    Last Post: 03-29-2011, 09:46 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