Well I had a thought last night.
Create a function to copy & paste the text into Word and then use whatever property holds the word count to get it's value?
That way you will always get what Word believes the count is.?
Well I had a thought last night.
Create a function to copy & paste the text into Word and then use whatever property holds the word count to get it's value?
That way you will always get what Word believes the count is.?
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Hmm, I pasted some text into word and then Debug.Print ActiveDocument.Words.Count and got 75, yet the status bar shows 69?
A Split() on a single space produces a Ubound of 68?, so 69 in all?
Found out why the discrepancy.
https://support.microsoft.com/en-us/...a-9da4ca22e3ff
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
I'm a novice about how to create functions. (Never did this before). Where would I start? If I went out to a 3rd party to create one for me to do that, how would I specify?
You do not need a third party, you have to start sometime.
I knocked this up to test my theory.
This will give you a start? Put the code into a module, then you can use it from anywhere?
If the Split function is what you need then, something along the lines of MyWordCount will suffice. It will also need a tweak to get rid of multiple spaces? Now amended to do the check
If you need the Word version (MyWordCount2), it is slower as it has to open word, plus you need the reference to the Word library.?
You then call it like soCode:Option Compare Database Option Explicit Public Function MyWordCount(strText As String) Dim strWords() As String Do While InStr(1, strText, " ") > 0 ' two spaces check strText = Replace(strText, " ", " ") Loop strWords = Split(strText, " ") MyWordCount = UBound(strWords) + 1 End Function Public Function MyWordCount2(strText As String) Dim objWord As Word.Application Dim strToCount As String Set objWord = CreateObject("Word.Application") objWord.Documents.Add objWord.Selection.TypeText (strText) objWord.ActiveDocument.Range.Select MyWordCount2 = objWord.ActiveDocument.Range.ComputeStatistics(wdStatisticWords) Set objWord = Nothing End Function
Code:Private Sub Command59_Click() Dim lngWordCount As Long lngWordCount = MyWordCount(Me.History96) MsgBox lngWordCount lngWordCount = MyWordCount2(Me.History96) MsgBox lngWordCount End Sub
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
I do appreciate the assistance, but I am not familiar with access programming. Can you direct me to a tutorial to get me started?
Lacking this, the code and instructions you have provided me (thank you, by the way), won't point me in the right direction.
You will have to say how you want to use it?
Pretend you have a form that holds the text in a memo field that is in a control txtNotes.
You also have a textbox txtWordCount that shows the number of words in txtNotes when you move out of txtNotes.
in the Control Source for txtWordCount you would put
if you wanted it all within AccessCode:=MywordCount(Me.txtNotes)
or
if you wanted the Word version.Code:=MywordCount2(Me.txtNotes)
You put all of the code in the first block into a module.
Alt + F11
Insert/Module
Then copy and paste all the first block into that new module, probably called Module1
You can rename it to whatever you want, just not the same as any of the function names (or any other names you have)
Have a look here https://www.youtube.com/results?sear...+for+beginners
HTH
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba