Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count words in a textbox vba

Status
Not open for further replies.

walejo89

Programmer
Jan 28, 2005
43
US
I have an access form and I have a textbox on the form. On this text box i am putting text and I need to count the number of words there are in that text box in order to get the total number and put it on a variable.
 
Try:
Code:
xArr = Split([yourtextbox], " ") ' Split on spaces
NumWords = UBound(xArr) + 1 ' add one to array upper bound
(with appropriate Dim statements, of course).

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
If you combine the functions you don't even need a variable:
[tt]
=UBound(Split(Me![txtWords])) + 1
[/tt]


VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
In case the text control is null, you might want to put in a test for that, too:

[tt]if (trim(Me!txtWord.valur & "")="") then
myvar = 0
else
myvar=UBound(Split(Me!txtWords.value)) + 1
end if[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top