Hi -
This will work in A97.
Function StrCount(ByVal TheStr As String, theItem As Variant) As Integer
'------------------------------------------------------------------
' Purpose: Counts the numbers of times an item occurs
' in a string.
' Coded by: raskew
' Arguments: TheStr: The string to be searched.
' TheItem: The item to search for.
' Returns: The number of occurences as an integer.
'
' Note: To test: Type '? StrCount("The quick brown fox jumped over
' the lazy dog", "the") in the debug window.
' The function returns 2.
'------------------------------------------------------------------
Dim i As Integer
Dim j As Integer
Dim placehold As Integer
Dim strHold As String
Dim itemhold As Variant
strHold = TheStr
itemhold = theItem
j = 0
If InStr(1, strHold, itemhold) 0 Then
While InStr(1, strHold, itemhold) 0
placehold = InStr(1, strHold, itemhold)
j = j + 1
strHold = Mid(strHold, placehold + Len(itemhold))
Wend
End If
StrCount = j
End Function
HTH - Bob
Jeff Smith wrote:
>Look for InStr in the help file
>MyString = "All men are created equal"
Debug.PrintLen(MyString)
[quoted text clipped - 10 lines]
>and the number of e's appearing in each
sentence?
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200703/1