Results 1 to 4 of 4
  1. #1
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71

    Automated Character Count for Text Box

    Ok, I am looking for a way to automatically count the number of characters that a user enters into a Text Box AS they type in the information.

    I know that if you setup a text box with the control source as "=Len([Field])" that it will display the count of characters in that field, however that is only after you move from the text box on the form will it update to reflect the number of characters entered. I have even gone so far as to in the On Key Down, On Key Press, On Key Up, and On Change events of the text box the user is entering the data to run the expression:



    Me.CharCount.Requery

    But it doesn't requery until a user moves off of the text box.

    Am I missing something here, or does anyone know of how to make this work, or am I wishing for something I can't have in Access 2007?

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    OK so we have 2 textboxes, one called txtType and one called txtCount.

    In the OnChange event of txtType, open the vba editor and enter:

    Me.txtCount = Len(Me.txtType.Text)

    One thing to note, however, is that the Len() function counts spaces as part of the string. Counting only the characters would be much more involved.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You are trying to count the wrong property. The text box (and other controls) have two properties of concern:

    the value property: what is currently entered
    the "text" property: wht is being entered into the control.

    So if you have two text boxes, "LastName" and "CharCount". In the on change event of the "LastName" text box is:
    Code:
    Private Sub LName_Change()
       Me.CharCount = Len(Me.LName.Text)
    End Sub
    Enter text into the "LastName" control and the count will be displayed in the "CharCount" control.

  4. #4
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    @TheShabz - Thanks for the info that in LEN spaces are also included in the count, which works for me since I am trying to keep users from exceeding the field lenght (and show them how many characters they have left).

    @TheShabz & ssanfu - using Len(Me.[FieldName].Text) worked beautifully!! Thanks for getting me back on track! I'm sure my users would also express their thanks as well!

    @ anyone who comes across this post -- I used the above but reversed the counter to show the remaining characters. So in the OnChange event I put in:

    Me.CharCount = 255 - Len(Me.Field.Text)

    Works like a charm!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Text Box control and character limit?
    By Bigdoggit in forum Forms
    Replies: 2
    Last Post: 03-29-2011, 10:05 AM
  2. Count Text as Number
    By AccessFreak in forum Forms
    Replies: 1
    Last Post: 01-04-2011, 12:49 PM
  3. Replies: 11
    Last Post: 07-20-2010, 06:55 AM
  4. help with totals for count text boxes
    By gacapp in forum Reports
    Replies: 10
    Last Post: 07-22-2009, 11:26 AM
  5. How to count charcter or text in field
    By nshaikh in forum Queries
    Replies: 3
    Last Post: 09-12-2008, 10:27 AM

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