Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IN operator used in If..Then (A2k)

    Hi All,
    Is it possible to use the IN operator in an If...Then statement? I know it works in an SQL Where, but if it does work in an If...Then, then I don't know how to code it.

    When I write
    If Whatever IN("choice1", "choice2", ... "choicen") Then
    I receive an "Expected: Then or GoTo" error after I hit the <enter> key after Then.
    Thanks.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: IN operator used in If..Then (A2k)

    As you note, IN is SQL. It is not valid in VBA. The nearest equivalent is probably

    Select Case Whatever
    Case "choice1", "choice2", ..., "choicen"
    ' do something
    Case Else
    ' do something else
    End Select

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: IN operator used in If..Then (A2k)

    Hi Hans,
    Yup, didn't think so, but it was worth a shot.
    Thanks.

    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •