Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2010
    Posts
    7

    Question Unanswered: Help with Counting Characters

    Is there anyway I can get access to count the letters in a memo field and not symbols or spaces?

    Thanks

    Katie

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    There are several ways to do this. This code, in the Click Event of a button, or in some other suitable event, will give you a count of characters without Spaces, Periods, Commas or Exclamation Points

    Code:
    Dim AlphaOnly As String
      
     If Nz(Me.FieldName, "") <> "" Then
      AlphaOnly = Me.FieldName
      AlphaOnly = Replace(AlphaOnly, " ", "") 'Dump Spaces
      AlphaOnly = Replace(AlphaOnly, ".", "") 'Dump Periods
      AlphaOnly = Replace(AlphaOnly, ",", "") 'Dump Commas
      AlphaOnly = Replace(AlphaOnly, "!", "") 'Dump Exclamation Points
      MsgBox Len(AlphaOnly)
     Else
      MsgBox "Field is Empty!"
     End If
    You can add code in a like manner for other symbols that need to be excluded.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Nov 2010
    Posts
    7
    Thanks, I thought there'd be a way!

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Another way would be:
    Code:
    Dim intCounter as Integer
    Dim AlphaOnlyCount As Integer
    
    AlphaOnlyCount = 0
    
    If Nz(Me.FieldName, "") <> "" Then
    For intCounter = 1 To Len(Me.FieldName)
    If Mid$(Me.FieldName, intCounter, 1) Like "[a-z]" Then
     AlphaOnlyCounter = AlphaOnlyCounter + 1
    End If
    Next
     MsgBox AlphaOnlyCounter
    Else
     MsgBox "Field is Empty!"
    End If
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2010
    Posts
    7
    Thanks, that second one looks slightly easier. I don't suppose there would be anyway to get it not to count letters between brackets? I'm trying to get counts of latin inscription lengths but the abbreviations are expanded i.e. 'h s est' becomes 'h(ic) s(itus) est'. I'm beginning to think the easiest thing to do would be to just count the letters I want by hand!

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    It would help if you could work out ALL the rules before requesting a solution. Any new rule might invalidate all the work done so far.

    Anyway, I think regex might be your best bet. If you used this function from the web (simply copy and paste) then the following works:
    Code:
    ?len(rgxReplace(rgxReplace("This is the string (here) and more", "[^a-z]"), "\(.+\)"))
    Result: 26
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Oops - hang on - my regex expression is wrong.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Fixed:
    Code:
    ?len(rgxReplace(rgxReplace("This is the string (here) and more (another bracket)", "\([^\(\)]+\)", , , True), "[^a-z]", , , True))
    returns 22.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Nov 2010
    Posts
    7
    Yeah, sorry about that. I thought I had...then realised I'd forgotten to take account of the expansions. Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •