using like in subroutine

  • Thread starter Thread starter kim de winter
  • Start date Start date
K

kim de winter

I'm trying to use the like operator in a subroutine but
for some reason I does not seem to work.

This is what I typed in the sub:

If rst2!fldfield1 = " Like ""*MILK*""" Then
yreq = (rst2!fldnrorder) * 2
Else
yreq = rst2!fldnrorder
End If

You see whenever the condition encounter thge
string 'MILK' then rst!fldnrorder should be multiplied by
2. Any help is most appreciated.
 
The Instr() function tells where one string begins within another, so:

If Instr(rst2!fldfield1, "MILK") > 0 Then
 
kim said:
I'm trying to use the like operator in a subroutine but
for some reason I does not seem to work.

This is what I typed in the sub:

If rst2!fldfield1 = " Like ""*MILK*""" Then
yreq = (rst2!fldnrorder) * 2
Else
yreq = rst2!fldnrorder
End If

You see whenever the condition encounter thge
string 'MILK' then rst!fldnrorder should be multiplied by
2. Any help is most appreciated.


You're mixing the exact match comparison operator "=" with
the partial match operator "Like". It should be either:

If rst2!fldfield1 = "MILK" Then
or
If rst2!fldfield1 Like "*MILK*" Then

depending on whether fldfield1 contains only "Milk" or
fldfield1 might have longer strings such as "A glass of milk
is good for you".
 
Back
Top