String Comparision?

  • Thread starter Thread starter Anthony Viscomi
  • Start date Start date
A

Anthony Viscomi

I have the following:
If Me.Option <> "increase" Then
Me.Base_Price.Value = Me.Option.Column(1)
End If

I want to check to see that the value of Me.Option does not equal
"increase", "decrease" or a number of other possible values (8 to be exact).
How can I achieve this?

Thanks!
Anthony
 
select case lcase(me.option)
case "increase","decrease","something", "something else"
' do something (or nothing)
case else
' do something else
end select

HTH
 
Thanks!
Alex Ivanov said:
select case lcase(me.option)
case "increase","decrease","something", "something else"
' do something (or nothing)
case else
' do something else
end select

HTH
 
The best way to solve multiple if's is to use the Select Case statement.
Although your logic seems a little obscure because you seem to be saying
check it ISN'T eight things and take action. Far better and more likely to
produce the desired result is to check what it is, and then do something thus:

Select Case Me("Option").Value
Case is = "increase"
Me("Base_Price").Value = whatever
Case is = "decrease"
Me("Base_Price").Value = whatever
Case is = "Option3"
Me("Base_Price").Value = whatever
Case is = "Option4"
Me("Base_Price").Value = whatever
Case Else
MsgBox Prompt:= "Non Valid Value"
End Select

Include the Case Else to catch an exception so your aware no action was
taken and not asuming that the record was correctly filled in.
If the only change is different numbers simplify the above by:

Dim TheValue as Integer

Select Case Me("Option").Value
Case is = "increase"
TheValue = 1
Case is = "decrease"
TheValue = 2
Case is = "Option3"
TheValue = 3
Case is = "Option4"
TheValue = 4
Case Else
MsgBox Prompt:= "Non Valid Value"
End Select
Me("Base_Price").Value = Me.Option.Column(TheValue)

Just remember that unlike the multiple If / End If your value will be
checked once through the Select Case, once a value is matched the appropriate
action will be taken and code will continue after the End Select.

Hope this helps.
Nigel
 
Back
Top