Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146

    Unanswered: Count characters in a field

    The logic behind this is simple and I've done something similar to this with controls on a form, but how does one go about counting characters (including spaces) in a field? I have a table that contains 2 fields, both of which are populated, and I need to output the total number of characters in them. I can easily perform this action on a form's control, but not sure how to perform it on all of the data within a field. Thanks for any advice.

  2. #2
    Join Date
    Sep 2004
    Location
    Charlotte, NC
    Posts
    164
    Len([FieldName]) or if you want the total characters of the 2 fields combined Len([Field1]&[Field2]).

    TD

  3. #3
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146
    Quote Originally Posted by buckeye_td
    Len([FieldName]) or if you want the total characters of the 2 fields combined Len([Field1]&[Field2]).

    TD
    Will this include spaces as well? And if so, just out of curiousity, what would the syntax look like for calculating without the spaces? Thanks for the reply.

  4. #4
    Join Date
    Sep 2004
    Location
    Charlotte, NC
    Posts
    164
    Yes, this will include all characters in the string including spaces. Right off hand, I'm not sure how I would search through a text string with the potential for multiple spaces and only count the other characters.

    TD

  5. #5
    Join Date
    Nov 2004
    Posts
    10
    well....

    len(Trim([field1]) & Trim([field2]))

    to get rid of leading and trailing spaces

    and

    len(Replace([field1] & [field2]," ",""))

    to get rid of all.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    As efflux says replace works, or even use the trim
    rtrim$(strmyvar) -remove leading spaces
    Ltrim$(strmyvar) -remove trailing spaces
    Trim$(strmyvar) - remove leading and trailing spaces
    replace will remove all spaces, including any inbetween words

  7. #7
    Join Date
    Dec 2004
    Posts
    4

    count

    How do you dynamically count the number of characters as you type them in the box while in a form?

    I need to limit the amount of characters in a memo field.

  8. #8
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Don't know how this will affect performance, but you could use the OnChange event for the control to check it's length after every keystroke.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  9. #9
    Join Date
    Feb 2002
    Posts
    108

    Count Field Characters as you type

    Quote Originally Posted by bluecloud View Post
    How do you dynamically count the number of characters as you type them in the box while in a form?

    I need to limit the amount of characters in a memo field.

    I realize this is old but in case anyone else looking for a solution like I was recently... this works for me...
    Add this code to the "on change" for the field whose characters you want to count as you type

    Refresh 'If you have any goto or setfocus statements that kick in when starting, you may have to rethink those...
    Me!txtTyping.SelStart = Me!txtTyping.SelLength
    txtCount=len(me!txtTyping)

Posting Permissions

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