Results 1 to 4 of 4
  1. #1
    BruceCovey is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2020
    Location
    Cartersville, Ga.
    Posts
    3

    SQL syntax to check if a value exists in any of 3 fields

    A bit rusty on my Access and needing to add functionality to an existing database… Any help would be greatly appreciated.

    I added 3 fields to my listSystems table ( funcSysName01, funcSysName02, funcSysName03 ) where a system/device can be a member of up to 3 Functional System groups. In the SQL below, the WHERE works fine when I enter a search value, but I really need to check all 3 fields with an OR. What is the correct syntax for this?


    SELECT listSystems.systemName, listSystems.frameName, [locationFacility] & "." & [locationBuilding] & "." & [locationFloor] & "." & [roomName] & "." & [locationRack] AS Location
    FROM listSystems
    WHERE (((listSystems.funcSysName01)=[enter FuncSysName]));

    Also… Any way in the Access Query Designer to have the entry screen for the WHERE to contain a drop-down list of values from a listTable?

  2. #2
    Minty is offline VIP
    Windows 11 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    You should probably store those as child records of the original table. If you ever get a 4th or 6th Functional group you will have to rebuild every thing.
    If they were in a child table it would be simple to check the child table for the presence of any records for the header record.

    If you want to pursue the current design (and I wouldn't) then something like;

    Code:
    WHERE listSystems.funcSysName01 = [enter FuncSysName] 
    OR listSystems.funcSysName02 = [enter FuncSysName] 
    OR listSystems.funcSysName03 = [enter FuncSysName] 
    
    
    To answer your second question you could put the available system functions names in a lookuptable and use a combo box on a form to refer to them and use the combo in the query.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    Learn to use the query design grid.
    Then you would put the criteria on to different rows for each funcSysName.

    As mentioned, anytime you start adding numbers to the same named field, your design is flawed.

    About the only time I would do that, is for Address fields, 1 to 6 plus a PostCode field.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,822
    Hi Bruce
    Can you upload a copy of your database?

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

Similar Threads

  1. Check if an index value exists
    By twgonder in forum Programming
    Replies: 19
    Last Post: 01-18-2024, 06:36 PM
  2. Replies: 6
    Last Post: 08-21-2019, 01:47 PM
  3. Check If Form Value Already Exists In Database
    By Richard_Marx in forum Modules
    Replies: 9
    Last Post: 08-15-2016, 09:32 AM
  4. Replies: 2
    Last Post: 03-02-2015, 12:19 PM
  5. Check if record exists, Check Number
    By burrina in forum Forms
    Replies: 9
    Last Post: 01-06-2013, 03:49 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