If statement against several values

  • Thread starter Thread starter wshall
  • Start date Start date
W

wshall

Is there a way to have an If statement compare against a few values
instead of just one? I need to convert some strings to convert some
reserved characters (& < > " and '). I would like to have an if
statement that checks for all of them... something like SQL's In
function:

WHERE strFind in ( '&', '>', '<' ..... etc

Is there some way to check against a list of items when using an if
statement?

Thanks!
 
Is there a way to have an If statement compare against a few values
instead of just one? I need to convert some strings to convert some
reserved characters (& < > " and '). I would like to have an if
statement that checks for all of them... something like SQL's In
function:

WHERE strFind in ( '&', '>', '<' ..... etc

Is there some way to check against a list of items when using an if
statement?

Thanks!

Try grabbing this function:

http://www.smccall.demon.co.uk/Strings.htm#ReplaceList

Then let's say you're converting these characters to HTML-safe expressions:

sResult = ReplaceList(strFind, "&", "&amp;", ">", "&gt;", "<", "&lt;")
 
Thanks, Stuart! I hadn't seen your code site before this. That's a
reason I like Access... lots of code samples to use as starting
places.

Your code would certainly work for this specific situation... but I'm
really trying to learn how to handle this kind of situation in the
future. I'm tried of having to enter repetative OR statements, such
as:

If chrTmp = "&" Or _
chrTmp = "<" Or _
chrTmp = ">" Or _
chrTmp = "'" Or _
chrTmp = """" Then

I'm wondering if there is a better way... something like SQL's IN
statement that I could use for future situations.

Any ideas?

Thanks!
 
Thanks, Stuart! I hadn't seen your code site before this. That's a
reason I like Access... lots of code samples to use as starting
places.

Your code would certainly work for this specific situation... but I'm
really trying to learn how to handle this kind of situation in the
future. I'm tried of having to enter repetative OR statements, such
as:

If chrTmp = "&" Or _
chrTmp = "<" Or _
chrTmp = ">" Or _
chrTmp = "'" Or _
chrTmp = """" Then

I'm wondering if there is a better way... something like SQL's IN
statement that I could use for future situations.

Any ideas?

Thanks!

Ok, when you have a single value and need to test multiple conditions, a
Select Case statement fits the bill better than If..Then.

Select Case chrTmp
Case "&", "<", ">", "'", """"
'Do whatever
Case Else
'chrTmp is none of the above
End Select
 
Back
Top