Add the following function to a standard module:
Public Function FindWord(strFindIn As String, strWord As String) As Boolean
Const PUNCLIST = " .,?!:;(){}[]"
Dim intPos As Integer
intPos = InStr(strFindIn, strWord)
If intPos > 0 Then
' is it at start of string
If intPos = 1 Then
' is it whole string?
If Len(strFindIn) = Len(strWord) Then
FindWord = True
Exit Function
' is it followed by a space or punctuation mark?
ElseIf InStr(PUNCLIST, Mid(strFindIn, intPos + Len(strWord), 1))
FindWord = True
Exit Function
End If
Else
' is it precedeed by a space or punctuation mark?
If InStr(PUNCLIST, Mid(strFindIn, intPos - 1, 1)) > 0 Then
' is it at end of string or followed by a space or
punctuation mark?
If InStr(PUNCLIST, Mid(strFindIn, intPos + Len(strWord), 1))
FindWord = True
Exit Function
End If
End If
End If
End If
End Function
As the ControlSource property of a text box on the firm use an expression
which calls the DCount function, with the above function called as its
criteria argument. If for instance you want to find the number of
occurrences of the word 'condensing' in the column the expression would be:
=DCount("*", "[YourTableName]", "FindWord([Boiler Type],""condensing"")")
The FindWord function assumes that a 'word' is either the whole contents of
the column or is a substring within the column, either at the start or
preceded by a space or a punctuation mark contained in the PUNCLIST constant,
or either at the end or followed by a space or a punctuation mark contained
in the PUNCLIST constant (which you can of course add to if necessary).
Rather than an embedded literal string such as ""condensing"" you can of
course use a variable such as the name of another control on the form which
contains the 'word' sought.
Ken Sheridan
Stafford, England
blake7 said:
Hi I have a database with a table, on fieldname is called "boiler type" I
would like to count the number of times a particular word appears in the
column and display this on a form in a text box, whats the best way ?
Thanks all