Results 1 to 6 of 6
  1. #1
    Ed Bitzer is offline Novice
    Windows 10 Office 365
    Join Date
    May 2025
    Posts
    17

    Where Query does not allow me to use Or to include two possible entries in field

    I have been programming in access for over 30 years but the brain is apparently fading at age 92. This where cause and I quote "WHERE (((SECURITY.SecType)="S" Or (SECURITY.SecType) = "E"));" works fine in a test query created in the designer but when created in a subroutine and executed it displays the "Error" that the where cause should stop after the first criteria. I just will not handle "OR". Now my old thinking is no matter what the quoted letter is the query should work, just not find that letter in my table. However the table does have both E's and S's.




    Now hopefully I am just an old guy that has forgot some obvious syntax difference from that created by the designer and that required when executed in code. On the other hand, you may require that I include the entire query which is a simple Select query.


    Appreciate,


    Ed

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Show your code!
    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

  3. #3
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    564
    Oh help. Abscess and it's love for parentheses.

    WHERE SECURITY.SecType="S" Or SECURITY.SecType = "E"

    or
    WHERE Security.SecType IN ("S","E")

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,739
    If you're creating this as an SQL string, those double quotes around embedded strings will be a problem. Do it this way with single quotes:
    WHERE SECURITY.SecType='S' Or SECURITY.SecType = 'E'

  5. #5
    Ed Bitzer is offline Novice
    Windows 10 Office 365
    Join Date
    May 2025
    Posts
    17
    Thanks guys. I have a weak excuse to not thanking you for the clue needed to solve this problem which was a simple as remember that SQL statements require handling variables and constants differently than that created by the "Designer." I had to add the necessary extra single quote followed by the regular quote and an & symbol. The excuse I was off on in the ER for a gushing nosebleed four times before they finally handled by cauterizing.

  6. #6
    Join Date
    Apr 2017
    Posts
    1,792
    Anyway, I'd advice you ise IN() instead of all those OR's (like Madpiet posted).
    Reasons:
    a) You avoid bloating your querystring (no problem with current 2 values, but why use different syntax for same thing when in future you need more of them listed in some query);
    b) You can use same syntax to use table or query instead of value list. Like
    IN(SomeTable)
    or
    IN(SomeSavedQuery)
    or
    IN(SELECT...)

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

Similar Threads

  1. Replies: 4
    Last Post: 07-13-2017, 09:41 AM
  2. Replies: 1
    Last Post: 03-10-2016, 04:12 PM
  3. Replies: 4
    Last Post: 02-17-2016, 01:53 PM
  4. Replies: 2
    Last Post: 01-20-2016, 12:41 PM
  5. Replies: 1
    Last Post: 06-14-2015, 09:48 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