Originally posted by Andrew Thackray
Count Words in a Field
Collapse
X
-
Very good exemple pks00!
The function that i've use was:
Function word_count(my_s entence, sep) As Integer
Dim result As Integer
Dim my_str
result = 1
Do While InStr(1, my_str, sep) > 0
result = result + 1
my_str = Mid(my_str, InStr(1, my_str, sep) + 1, Len(my_str))
Loop
word_count = result
End Function
But yours it's great!
Best regards!
Originally posted by pks00What if u used the Split command?
Code:Dim sWords() as String sWords = Split(myfield," ") msgbox "Number of words is " & ubound(sWords)
Comment
-
:)
Ok my friend, we've done a big discussion about your problem...
But you need to select a function it's better the suggestion of pks00 copy from thescripts and
in access go in modules, choose New module and Paste there the function
Save it...
To obtain the word count in a column in your query:
Create a query add your table or query on which should be based the new one.
In an empty column write the name of the choosen function and between the () instaed the name inside, put the name of the column that contain the text that you want to get the countComment
-
Code:public function word_count(InWord as variant) as Integer dim words() as string word_str=nz(word_str,"") 'deals with null values passed in word_str = replace(word_str,vbcr," ") ' Whatever you want to also delineate a word can be placed here. while instr(word_str," ") > 0 ) 'Check to see if double spaces word_str = replace(word_str," "," ") ' change double to single space wend words = split(word_str," ") word_count = ubound(words) + 1 end function
Comment
-
Comment