select case like?

  • Thread starter Thread starter LindaF
  • Start date Start date
L

LindaF

Can you use a Case statement to evaluate a field equivalent to using Like e.g.

Select Case Desc
Case is like "*Interest*" ' i.e. the field Desc contains the
characters Interest
do ............
Case Else
do ...........
End Select
 
Can you use a Case statement to evaluate a field equivalent to using Like e.g.

Select Case Desc
Case is like "*Interest*" ' i.e. the field Desc contains the
characters Interest
do ............
Case Else
do ...........
End Select

Doesn't that throw a specific error on the word like?

Do it this way:

Dim intA As Integer
intA = InStr([Desc], "Interest")

Select Case intA
Case Is > 0
' Yes that word is there
Case Is = 20
' Nope it's not there
End Select
 
I am trying to simplify my code from using a number of nested if statements
which mostly include searching for a different string in the description
field. Not sure whether this would make my code simpler but thanks for the
quick reply.

Linda

fredg said:
Can you use a Case statement to evaluate a field equivalent to using Like e.g.

Select Case Desc
Case is like "*Interest*" ' i.e. the field Desc contains the
characters Interest
do ............
Case Else
do ...........
End Select

Doesn't that throw a specific error on the word like?

Do it this way:

Dim intA As Integer
intA = InStr([Desc], "Interest")

Select Case intA
Case Is > 0
' Yes that word is there
Case Is = 20
' Nope it's not there
End Select
 
Can you use a Case statement to evaluate a field equivalent to using Likee.g.

Select Case Desc
          Case is like "*Interest*"   ' i.e. the field Desc contains the
characters Interest
                  do ............
           Case Else
                  do ...........
End Select

Maybe you can use something like

Select Case True
Case Instr(1, [Desc], "Interest")>0
Do
...
Loop
Case
....
End Select
 
I will try that.
Thanks
Linda

Piet Linden said:
Can you use a Case statement to evaluate a field equivalent to using Like e.g.

Select Case Desc
Case is like "*Interest*" ' i.e. the field Desc contains the
characters Interest
do ............
Case Else
do ...........
End Select

Maybe you can use something like

Select Case True
Case Instr(1, [Desc], "Interest")>0
Do
...
Loop
Case
....
End Select
 
No you can't do that with a case statement but you can use

IF DESC LIKE "*Interest*" Then
...
ELSEIF DESC Like "*Rate*" Then
...
ELSEIF Desc Like "*Spencer*" Then

...
Else 'Handle all other cases

End if

I did see an example posted like this one time. I never tried to see if
this would actually work or not. You might experiment and post your
results back.

SELECT Case TRUE
Case DESC LIKE "*Interest*"
Case DESC Like "*Rate*"
Case Desc Like "*Spencer*"
Case Else
END Select
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
Thanks worked like a dream

Linda

John Spencer said:
No you can't do that with a case statement but you can use

IF DESC LIKE "*Interest*" Then
...
ELSEIF DESC Like "*Rate*" Then
...
ELSEIF Desc Like "*Spencer*" Then

...
Else 'Handle all other cases

End if

I did see an example posted like this one time. I never tried to see if
this would actually work or not. You might experiment and post your
results back.

SELECT Case TRUE
Case DESC LIKE "*Interest*"
Case DESC Like "*Rate*"
Case Desc Like "*Spencer*"
Case Else
END Select
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
Just out of curiosity, which of the two proposed solutions did you use?

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
I used SELECT Case TRUE

I already had a lot of IF statements and was able to tidy up the code using
the CASE statement
 
Back
Top