Results 1 to 5 of 5

Syntax for OR in an IF statement

  1. #1
    swenger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    133

    Syntax for OR in an IF statement


    If SM = 6 Or 8 Or 13 Or 14 Then
    ...

    it doesn't seem to like the Syntax above. no error but condition not working. What is the proper syntax to check for a result using the OR

    Thanks

    Sam

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    20,719
    You have to repeat the field:

    If SM = 6 OR SM = 8...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    swenger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    133
    Thanks. That's a bummer. Hoping there was a way which out repeating.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    20,719
    No problem. In SQL you can use In(), but not in VBA (I don't think anyway).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,432
    Maybe a bummer as you say, but makes perfect sense when you consider a processor can't reason as you do and has no concept of how language is interpreted. 10 out of 10 people would likely understand what that means because of the way we communicate but a computer is 100% literal. Thus each portion of that logic must be able to stand on its own. Your syntax then becomes

    If SM = 6 <- anyone can interpret that line, but what if I just said to you

    Or 8
    Or 13
    Or 14
    You'd look at me like I was on drugs, yet that's what you're saying to a pc. I point out the reason so that you can carry this thinking forward to every situation in the future so that you are just as literal.

    BTW another form for a bunch of ORs is a Select Case block:

    Code:
    Select Case SM
     Case 8
       do this
     Case 10
      do this
     Case 12
      do this
    Case Else
     do that
    End Select
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.

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

Similar Threads

  1. Syntax on Iif Statement?
    By aellistechsupport in forum Queries
    Replies: 9
    Last Post: 07-12-2017, 03:33 PM
  2. syntax for if then statement
    By crowegreg in forum Forms
    Replies: 3
    Last Post: 09-05-2013, 03:33 PM
  3. Syntax of rs.Open Statement
    By Philosophaie in forum Access
    Replies: 5
    Last Post: 07-05-2013, 06:24 PM
  4. If statement syntax help!
    By Richie27 in forum Programming
    Replies: 15
    Last Post: 06-15-2012, 12:58 AM
  5. Replies: 7
    Last Post: 08-17-2011, 01: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
  •  
Tech Forums: Microsoft Office Forums