Results 1 to 5 of 5
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754

    Adding an IF Statement to a Select ?

    HI all,
    Is it possible to add an if statement to a combo select statement?
    Code:
    SELECT [CountyTbl].[CountyD], [CountyTbl].[CountyName] FROM CountyTbl ORDER BY [CountyName];
    I want to add an if statement to above If Not Null (CountyName) so if countyname is null, then it doesn't show up in my combo



    Any suggestions?
    Thanks
    Dave

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Not in SQL. Use IIF, or SWITCH
    when using a combo, swap Combo query depending,

    Code:
    sub cboCountry_afterupdate()
    if isnull(cboCountry) then
       CboBox.sourceobject ="qsNoCountry"
    else
         CboBox.sourceobject ="qs1Country"
    end if
    end sub

  3. #3
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Dave, if I get it right, you should be write the sql statement like this:
    Code:
    SELECT [CountyTbl].[CountyD], [CountyTbl].[CountyName] FROM CountyTbl WHERE [CountyTbl].[CountyName] Is Not Null ORDER BY [CountyName];
    Search for "SQL WHERE clause"

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why would a record in CountyTbl not have county name?

    Is field name actually CountyD, not CountyID?
    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.

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754
    thanks to all, and yes, it is CountyID, that's my mistake. just for the record, I have military addresses that do not have counties when I ship to them. I think I can see this as solved. Thanks to all for the advice!

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

Similar Threads

  1. Adding if statement
    By bradp1979 in forum Queries
    Replies: 9
    Last Post: 12-28-2015, 05:36 PM
  2. Adding a Count function to current select statement
    By johnson8809 in forum Queries
    Replies: 2
    Last Post: 02-21-2015, 07:32 PM
  3. Should I /can I use a Select Case statement?
    By Gina Maylone in forum Access
    Replies: 1
    Last Post: 12-13-2014, 12:08 PM
  4. Need a select statement
    By gahawy in forum Queries
    Replies: 5
    Last Post: 01-15-2011, 04:02 PM
  5. select statement
    By jellybeannn in forum Access
    Replies: 5
    Last Post: 08-13-2010, 05:21 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