Count Words/Spaces

  • Thread starter Thread starter Guest
  • Start date Start date
In just a normal text box...often the user will use the enter key to start a
new line


one
two
three

There is no spaces in the above..as each word in the text box is on a new
line. So, do your users hit ctrl-enter? Or, in fact did you set the enter
key in the "other" tab to actually start a new line in the text box?

So, really, it is possible that you want to could more then just spaces....

The way I would approach this is to change line new lines into a space, and
do a count.

dim strBuf as string

strBuf = replace(me.MyTxtBox,vbCrLf, " ")

intWordCount = ubound(split(strBuf," "))

The above will give you the number of spaces...and the word could would be +
1. So,
words...and presumably ..this is the number of spaces less one.....
intWordCount = intWordCount + 1
 
Yeah, your right i am a just a novice could you please provide me with a
public function to call this procedure.
 
That code I posted should work. We can wrap it in a nice function name,a nd
place it in a standard module:

eg:

Public Function MyWordCount(vText As Variant) As Integer

Dim strBuf As String

MyWordCount = 0

If IsNull(vText) = True Then
Exit Function
End If

strBuf = Replace(vText, vbCrLf, " ")

MyWordCount = UBound(Split(strBuf, " ")) + 1


End Function

Now, you can use the following expression in a text box you place on a form

=(MyWordCount([YouFieldName])

You can also use the above expression in a report..or even a query....
 
Back
Top