Results 1 to 4 of 4
  1. #1
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146

    vba syntax for multiple OR's

    This works for me...



    Code:
    Sub Check1()        If strCheck1 = "C-5" Then
                strMachine = strCheck1
            ElseIf strCheck1 = "C-6" Then
                strMachine = strCheck1
            ElseIf strCheck1 = "C-7" Then
                strMachine = strCheck1
            ElseIf strCheck1 = "C-8" Then
                strMachine = strCheck1
            Else
                strMachine = Null
            End If
    End Sub
    but why can't i put multiple OR's on one line? like this:

    Code:
    Sub Check1()
            If strCheck1 = "C-5" or "C-6" or "C-7" or "C-8" Then
                strMachine = strCheck1
            Else
                strMachine = Null
            End If
    End Sub

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

    If strCheck1 = "C-5" or strCheck1 "C-6" ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146
    I see.... Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. Hopefully you saw my missing =. Should be:

    If strCheck1 = "C-5" or strCheck1 = "C-6" ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. proper syntax for where clause with multiple
    By vicsaccess in forum Programming
    Replies: 3
    Last Post: 02-14-2016, 09:29 PM
  2. multiple inner joins getting syntax error
    By ringram in forum Modules
    Replies: 5
    Last Post: 10-23-2014, 02:58 PM
  3. Replies: 2
    Last Post: 02-26-2014, 05:06 PM
  4. Davg Multiple Criteria Syntax
    By JonathanT in forum Programming
    Replies: 1
    Last Post: 10-30-2013, 10:16 PM
  5. Replies: 7
    Last Post: 06-28-2013, 12:15 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