Re: Compact Syntax for OR Condition

Tech-Archive recommends: Fix windows errors by optimizing your registry



In news:C17C5011-EA12-42AD-9221-5AE9B7BB853A@xxxxxxxxxxxxx,
DevDaniel <DevDaniel@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I have: a long list of OR conditions
e.g., var = apples OR var = bananas OR var = oranges

Is there a compact way of expressing this, like in SQL
e.g., var In (apples, bananas, oranges)

In VBA there's no "In" operator, unfortunately. A Select statement
might be somewhat more compact than a long list of "Or"s:

Select Case var
Case apples, bananas, oranges
' do something
End Select

Or you could use an InStr expression like this:

If InStr("/" & var & "/", "/apples/bananas/oranges/") > 0 Then

In such an expression, you have to choose a delimiter ("/" in the
example above) that doesn't occur in any of the values to be checked.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.



Relevant Pages

  • What is the best way to load this tree (c# & sql question)
    ... Say you have three tables apples, oranges and bananas and each table has a ... bananas) And second it won't work because I don't have a sql statement ... unions but due to the unequal amount of fields it's not working out for me. ...
    (microsoft.public.dotnet.languages.csharp)
  • Replace characters from cell values
    ... I would like to remove the number and dash from the cell values as ... - Apples ... - Oranges ... - Bananas ...
    (microsoft.public.excel.programming)
  • RE: countif bigger than zero fractions
    ... the distinction to see the number of apples possible in a container. ... I'm guessing that the 1/2 quantity for Bananas is text, ... I want to use a Countif function or something similar to add up the total ... if I leave Oranges blank it ...
    (microsoft.public.excel.worksheet.functions)
  • controlling one list box by another
    ... fruits from the lstBox1, ... I'd like the lstBox2 to show apples, oranges, & bananas. ...
    (microsoft.public.access.forms)
  • Re: Androcless accusations of lying
    ... ct is scalar multiple of x, otherwise it may already be squewed or ... Oranges, and apples, if you like. ... Of course, I'm talking about real physics and sanity, not theoretical ...
    (sci.physics.relativity)