UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Find Exact String Within A String, Access 2016    
 
   
TimTDP
post Feb 26 2019, 07:00 AM
Post#1



Posts: 1,099
Joined: 16-June 05



I have 2 records in a field
Record 1 = "The cat sat in the mat"
Record 2= "mat"

In vba, I need to run a loop that only returns record 2

e.g InStr(1, FieldName , "mat", vbTextCompare)

How do I search for an exact string within a string?

Thanks
Go to the top of the page
 
BruceM
post Feb 26 2019, 07:27 AM
Post#2


UtterAccess VIP
Posts: 7,971
Joined: 24-May 10
From: Downeast Maine


What you have shown will do what you describe, but will return both records. In the first case it will return 20. In the second it will return 1. If you are looking for an exact match (in this case, "mat" and nothing else, you could do a direct comparison:

If Field1 = "mat" Then...
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th October 2019 - 02:39 PM