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    
post Feb 26 2019, 07:00 AM

Posts: 1,101
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?

Go to the top of the page
post Feb 26 2019, 07:27 AM

UtterAccess VIP
Posts: 8,014
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    25th January 2020 - 05:25 AM