A Like statement is used to determine if a Row is to be returned as part of a RecordSet for a SQL Select. So it is working as it should to let you know that the Row has the word you are looking for.
What you'll need to do for each Row it to perform a Count on the particular Field. There is no native way to do that, that I know of, so you will have to resort to programming. This function will give you the Count:
- Public Function getWordCount(ByRef sSentence As String, ByRef sWord As String) As Integer
-
Dim RegEx As Object
-
Dim regexMatches As Object
-
Dim oReturn As Variant
-
-
Set RegEx = CreateObject("VBScript.RegExp")
-
RegEx.MultiLine = False
-
RegEx.Global = True
-
RegEx.IgnoreCase = False
-
-
RegEx.Pattern = "[" & sWord & "]+"
-
Set regexMatches = RegEx.Execute(sSentence)
-
-
getWordCount = regexMatches.Count
-
End Function
You can then include the function as part of your query, like:
- SELECT Books.Title, getWordCount([Books]![Title],[Forms]![Form2]![txtCriteria]) AS WordCount
-
FROM Books;