word count

  • Thread starter Thread starter jebuntin
  • Start date Start date
J

jebuntin

Guest
Is there any way to calculate how many words there are in a memo field? And also maybe limit the amount of words that can be entered?
 
This code will count the number of words in a memo field when the control has lost the focus. It could also be used on OnUpdate.

Private Sub mmoSecond_LostFocus()
Dim First$ 'Variable to hold memo string
Dim arr As Variant 'Variable to hold string when split (array)
Dim n% 'Variable to hold number of words (size of Array)
First$ = mmoSecond.Text 'Get text from Memo field
First$ = Replace(First$, " ", " ", 1) 'Remove double spaces
arr = Split(First$, " ") 'Split up into individual words
n% = UBound(arr) + 1 'Find size of Array
txtFirst.SetFocus 'Set focus to text field to display number of words
txtFirst.Text = n% 'Set the value of the text field
End Sub

Sned
 

Users who are viewing this thread

Back
Top Bottom