Unfortunately, that's going to give an incorrect count if more than
one space exists between words:
?UBound(Split("This should be five words.", " "))+1
5
?UBound(Split("This should be five words.", " "))+1
9
You may also want a function to change all multiple spaces to a
single space, like
Function SingleSpaces(InputString As String) As String
Dim strWorkString As String
strWorkString = InputString
Do While InStr(strWorkString, " ") > 0
strWorkString = Replace(strWorkString, " ", " ")
Loop
SingleSpaces = strWorkString
End Function
?UBound(Split(SingleSpaces("This should be five words."), " "))+1
5
?UBound(Split(SingleSpaces("This should be five words."), "
"))+1 5
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Sprinks said:
AA,
A custom function placed in a global module should do the trick:
Public Function WordCount(strParam) As Long
Dim astrParsedField() As String
If Not IsNull(strParam) Then
' Parse string into an array
astrParsedField = Split(strParam, " ")
WordCount = UBound(astrParsedField) + 1
Else
WordCount = 0
End If
End Function
Set the textbox' ControlSource to:
=WordCount([YourTextbox])
Sprinks
:
Hi,
I have a straight simple but nasty issue troubling me.
I want to have a word count in a every row on a text field.
Guru's please help!
Thanks
AA