Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    jimk100189 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2021
    Posts
    4

    CIs there a way to do a word count on a text field?

    In Word 2013, I can do a word count on a document under REVIEW.
    Does such a thing exist in ACCESS 2013?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    youd have to write your own, or get one from this forum.

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi

    Use this Function

    Code:
    Function WordCount(ByRef Str As String) As Long
     
        Dim cnt As Long
        Dim Words As Long
     
        Words = 0
        WordCount = 0
        If Len(Str) = 0 Then
            Exit Function
        End If
        For cnt = 1 To Len(Str)
            Select Case Mid(Str, cnt, 1)
                Case " "
                    Words = Words + 1
                Case "."
                    Words = Words + 1
                Case ","
                    Words = Words + 1
                Case ";"
                    Words = Words + 1
                Case ":"
                    Words = Words + 1
                Case "-"
                    Words = Words + 1
            End Select
        Next cnt
        If Words = 0 Then Words = 1
        WordCount = Words
    End Function
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Then in a query you can use this:-

    Count: Wordcount(Nz([Item_Notes],""))
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by mike60smart View Post
    Hi

    Use this Function

    Code:
    Function WordCount(ByRef Str As String) As Long
     
        Dim cnt As Long
        Dim Words As Long
     
        Words = 0
        WordCount = 0
        If Len(Str) = 0 Then
            Exit Function
        End If
        For cnt = 1 To Len(Str)
            Select Case Mid(Str, cnt, 1)
                Case " "
                    Words = Words + 1
                Case "."
                    Words = Words + 1
                Case ","
                    Words = Words + 1
                Case ";"
                    Words = Words + 1
                Case ":"
                    Words = Words + 1
                Case "-"
                    Words = Words + 1
            End Select
        Next cnt
        If Words = 0 Then Words = 1
        WordCount = Words
    End Function
    @mike60smart
    I had always thought hyphenated words counted as 1?.
    Hyphenated words in Word do count as 1?
    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

  6. #6
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Welshgasman

    The function used in a query produced the following results:-
    Attached Thumbnails Attached Thumbnails Output.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    They are not hyphenated though?, there is a space each side of the "-" character?

    Plus
    Additional detail – WW ROHS shows up as 4 words in Word?

    Additional detail – WW ROHS, 1.5x batt = 3600mAh shows up as 8 words ?

    I cannot really see if your , in the last entry has a space after it, but would make it worse if it does not?
    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

  8. #8
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Yes The function appears to count the Hyphens and the Comma as a word so not 100% accurate.

    I would imagine the Function needs tweaking slightly to ignore Hyphens & Commas. I would not have a clue as to how it can be tweeked as
    my VB Skills are minimal.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I was thinking of using the Split() function with a space?
    If a word ends with a , it is still one word?, same for other characters.?

    If for some reason multiple delimiters are needed then this link shows a way.
    https://stackoverflow.com/questions/...s-in-vba-excel

    Only the O/P knows what he needs, but I was going on what Word produces as a word count.

    Thorough testing would be required of course?
    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

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Word must have its own definition. I just tested a sql statement in Word and the result was 48. IMO that is only about 50 words short of what I would count.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I used Micron's response
    Word must have its own definition. I just tested a sql statement in Word and the result was 48. IMO that is only about 50 words short of what I would count.
    Just replace each space with space--> gives me 32 which seems to match the word count.
    So counting spaces may be quick and dirty method. How exact must your count be?

  12. #12
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    @orange, what is the input for that comment? I don't understand. Surely it's not the record that's counted as 10?
    What I've not seen yet is an input and expected result from OP and until we get that I'm going to sit on the sidelines.
    WW
    ROHS
    1.5x
    batt
    3600mAh
    IMO, that field is 5 words but the exact words are unknown because of the lack of info. If = is not a word, then which of these is the word: 1.5 or 1.5x since x is also a mathematical symbol, just like = ? Perhaps the count is more important so it doesn't matter, but I dare say there will be cases where lack of tight rules could be an issue. At best, I think an approximation is all that could be hoped for.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    micron,
    I quoted your response post #10. And used that.
    I copied the 2 sentences, pasted in Notepad++ and replaced space with space. 32 replacements.

    Now if you have user inputted text, I would suggest you remove all double (or more) contiguous spaces to single space, then do the replace. Seems it could be a fairly simple function, but accuracy and specific instruction/requirement details needed before any further suggestions.

    A function:
    Code:
    ' ----------------------------------------------------------------
    ' Procedure Name: GetWordCount
    ' Purpose: Get a word count from a string based on number of spaces in the input
    ' Procedure Kind: Function
    ' Procedure Access: Public
    ' Parameter s (String): the string to be parsed for word count
    ' Return Type: Integer
    ' Author: Jack
    ' Date: 01-Jul-21
    ' ----------------------------------------------------------------
    Function GetWordCount(s As String) As Integer
    
        Dim StringIn As Variant
        If Len(s) = 0 Then
            GetWordCount = 0
        Else
            StringIn = Split(s, " ")
            GetWordCount = UBound(StringIn) + 1 'must account for array element(0)
        End If
    End Function

  14. #14
    jimk100189 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2021
    Posts
    4
    Quote Originally Posted by Welshgasman View Post
    I was thinking of using the Split() function with a space?
    If a word ends with a , it is still one word?, same for other characters.?

    If for some reason multiple delimiters are needed then this link shows a way.
    https://stackoverflow.com/questions/...s-in-vba-excel

    Only the O/P knows what he needs, but I was going on what Word produces as a word count.

    Thorough testing would be required of course?
    YES : Yes, word count is what I'm trying to get. In MS Word REVIEW tab the WORD FOUNT function provides
    Pages
    Words
    Characters (With spaces)
    Characters (Without spaces)
    Paragragraphs, and
    Lines

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Post 14 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-23-2019, 10:27 AM
  2. Replies: 2
    Last Post: 11-01-2016, 07:32 AM
  3. Replies: 4
    Last Post: 08-07-2015, 07:49 AM
  4. Replies: 1
    Last Post: 08-04-2011, 04:17 PM
  5. OLE and Text Field with MS Word
    By WBlohm in forum Programming
    Replies: 0
    Last Post: 09-09-2010, 12:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums