Question If then using a list

Lanason

Registered User.
Local time
Today, 09:44
Joined
Sep 12, 2003
Messages
258
I want to do an "if then" statement in my code, but to see if it matches a list

something list :-
if A= 1 or 2 or 7 or 9 then
but this syntax is wrong
so i need something like
if A= 1,2,7,9 then

is there a slick way to do this?:confused:
 
Select Case is the right way to go, but just to be clear. When using If, you should make sure you apply the conditions explicitly.
Code:
If A = 1 Or [COLOR=Red][B]A = [/B][/COLOR]2 Or[COLOR=Red][B] A = [/B][/COLOR]7 Or [COLOR=Red][B]A = [/B][/COLOR]9 then
   [COLOR=Green] 'do something[/COLOR]
 
I don't want to do different thing depending on the value just to do one thing based upon if the condition is one of a list of possible options
 
So...........

I am not sure what your reply is supposed to mean. You are using If or Select? Both could be the answer.
 
I wonder if the Lanason would benefit from having this list put in a table and joined against the other table.

I suppose we need to know what the point of this check is.
 
I wonder if the Lanason would benefit from having this list put in a table and joined against the other table.

I suppose we need to know what the point of this check is.

I have a number of stores and when I create a new part number I want to email a notification, but only for certain stores not for the rest and be able to edit the list easily

code like:-
if ([StoreCode]=1 or [StoreCode]=3 or [StoreCode]=7 or [StoreCode]=9 or [StoreCode]=11 or [StoreCode]=12 or [StoreCode]=14 or [StoreCode]=17 or [StoreCode]=33 or [StoreCode]=41 or [StoreCode]=51 then
seems long winded and messy
 
Go with the solution vbaInet has described. Use a table. Easy to manage, far less coding, and easy to add to the store code in future.
 
The solution would be

A. Build a "validate this action" table and populate it with the store numbers for which you do or don't want something done.

B. Use syntax such as "WHERE StoreNumb IN ( SELECT StoreNo FROM StoreValidation )" as part of your selection criteria. This assumes that [StoreNo] is in your validation table and [StoreNumb] is the number you are testing to see if it is right.
 

Users who are viewing this thread

Back
Top Bottom