Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2010
    Posts
    22

    Unanswered: If Then Statement Using OR

    Hello Everyone,

    I’m currently trying to use the following format which doesn’t work:

    If rst![Departure] = ("Home" Or "School" Or "Church") OR rst![Arrival] = ("Home" Or "School" Or "Church") Then ...

    Using a comma instead of the Or don’t work either.

    Other than using the long format below, is there some way to accomplish testing different conditions?

    If rst![Departure] = ("Home”) OR
    If rst![Departure] = ("School") OR
    If rst![Departure] = ("Church")

    OR

    If rst![Arrival] = ("Home”) OR
    If rst![Arrival] = ("School") OR
    If rst![Arrival] = ("Church")

    Thanks for any help!

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    If rst![Departure] IN ('Home','School','Church') 
    Or rst![Arrival]   IN ('Home','School','Church') 
    Then ...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2010
    Posts
    22
    Thanks for the reply. This was one of the options I'd tried that didn't previously work. Just in case, I'd used double quotes before I re-tried it and still received the following compile error which highlights the "IN": Expected Then or GoTo.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can't use IN like that in VBA, it's only recognized by the SQL engine. Try:
    Code:
    If Eval("'" & rst!Departure & "' IN ( 'Home', 'School', 'Church' ) OR '" & rst!Arrival & "' IN (  'Home', 'School', 'Church' )") = True Then
    This works because Eval() can invoke the SQL engine of Access to produce an evaluation.
    Have a nice day!

  5. #5
    Join Date
    Dec 2010
    Posts
    22
    Works great. It will be even better for me once I get the line continuation to work! Thanks a lot.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Tags for this Thread

Posting Permissions

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