select case like?

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
 
F

fredg

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
 
L

LindaF

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
 
P

Piet Linden

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
 
L

LindaF

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
 
J

John Spencer

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
'====================================================
 
L

LindaF

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
'====================================================
 
J

John Spencer

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
'====================================================
 
L

LindaF

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top