using like in subroutine

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.
 
A

Allen Browne

The Instr() function tells where one string begins within another, so:

If Instr(rst2!fldfield1, "MILK") > 0 Then
 
M

Marshall Barton

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".
 

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