Need vba expression to test for a word in a field

  • Thread starter Thread starter tted78
  • Start date Start date
T

tted78

I need a way to test a particular text field in a table for the presence of a
particular word. I have tried "If (field1 contains "test")" without success.
Is there a means to do this in vba for Access 2007? Thank you
 
Try this:

Use the Instr() function (Check the help file for details)

SELECT InStr([Field1],"Text") AS DataFound
FROM tblData
WHERE (((InStr([Field1],"Text"))>0));

That will check for the existence of "Text" within Field1.


Regards

Kevin
 
You can also use a like operator.

IF Field1 LIKE "*TEXT*" THEN
'Do something

I would probably use Instr function unless I needed to use wildcard characters
in the match.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

kc-mass said:
Try this:

Use the Instr() function (Check the help file for details)

SELECT InStr([Field1],"Text") AS DataFound
FROM tblData
WHERE (((InStr([Field1],"Text"))>0));

That will check for the existence of "Text" within Field1.


Regards

Kevin



tted78 said:
I need a way to test a particular text field in a table for the presence of
a
particular word. I have tried "If (field1 contains "test")" without
success.
Is there a means to do this in vba for Access 2007? Thank you
 
Back
Top