473,408 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

What event would I use to count characters WHILE typing?

Hi,

While the user is typing into a text box, I need to display the length of the string they are typing. My code is...

displayCountLabel.caption = len(me!fieldTheyAreTypingIn)

Problem is that I can't seem to find an event that occurs while the user continuously types. I tried keydown and keyup and keypress. All of them fire on the first occurence but they do not keep firing as the user continues to type.

Does anyone know how I can do this?

Thanks
Adam
Sep 6 '08 #1
12 17219
missinglinq
3,532 Expert 2GB
You have to use the Change event of your textbox. This displays the character count in a label named CharacterCountLabel.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_Change()
  2.   CharacterCountLabel.Caption = Len(Me.YourTextBox.Text)
  3. End Sub
This method lets the user know how many characters they have left to type, then pops a warning box when they reach the limit. In this demo the limit is 255, but that number can be changes.

Place a label above or next to the textbox.
Make the label's saption "255 Characters Left"
Place this code behind the textbox:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_Change()
  2.   CharacterCountLabel.Caption = 255 - Len(Me.YourTextBox.Text) & " Characters Left"
  3.   If Len(Me.YourTextBox.Text) = 255 Then
  4.     MsgBox "No more characters allowed!"
  5.   End If
  6. End Sub
Linq ;0)>
Sep 6 '08 #2
NeoPa
32,556 Expert Mod 16PB
Wow!!

Quick and impressive Linq ;)
Sep 6 '08 #3
missinglinq
3,532 Expert 2GB
Been asked and answered before! I keep a folder full of hacks I've written before for posts. The trick, at my advanced age, is remembering what the devil I named the file!

;0)>
Sep 6 '08 #4
NeoPa
32,556 Expert Mod 16PB
For someone who should do better, I make a poor job of keeping a tally of all those too :(
Sep 6 '08 #5
Perfect! Thanks

Interesting, when I tried referencing the text field as

me!myTextField

it didn't work. I had to use

me!myTextField.text

I always thought .text was the default.

Any way, thanks again

Adam
Sep 6 '08 #6
NeoPa
32,556 Expert Mod 16PB
The default is actually Me.myTextField.Value, however, this should also return the same as .Text with text data in the control.

If you're interested I could look at the code for you. Make it clear what happens with the code you post (that doesn't work) though.
Sep 6 '08 #7
I already typed over it and I'm not exactly sure how I had it. Besides, I don't want to put you out further. I'm up and running. Thanks!
Sep 6 '08 #8
NeoPa
32,556 Expert Mod 16PB
That's fine. You're happy. That's the most important thing :)
Sep 6 '08 #9
missinglinq
3,532 Expert 2GB
myTextField.Value is actually Null until data is saved in the field for the first time, so myTextField.Text can have data while myTextField.Value doesn't.

If you were to enter and save the word silver in myTextField, myTextField.Value would be silver. If you were to now enter the word gold in myTextField, leave the cursor in the textbox and check, myTextField.Value would still be silver even though myTextField.Text is gold and gold actually shows in the textbox.

Confusing, isn't it?

Linq ;0)>.
Sep 6 '08 #10
NeoPa
32,556 Expert Mod 16PB
Of course!

This is all while still typing in the field. That makes better sense now.
Sep 6 '08 #11
missinglinq
3,532 Expert 2GB
I think the confusion over this comes because in straight Visual Basic the Default Property of a textbox is Text, as opposed to VBA where it's Value. In retrospect, Microsoft probably would have done better to use a name like Basic For Applications, which would have yielded BFA and maybe wouldn't have been as likely to be confused with VB..

Linq ;0)>
Sep 7 '08 #12
I am just getting to know this Access thing, and at 65 the process is equally slow.. your help with this one was great. Thank you.
Nov 7 '14 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Susan Bricker | last post by:
Greetings. I have a Mainform with a subform. The Mainform has single record format and subform has continuous form format. When the Mainform opens, I force allowadditions and allowedits to FALSE...
3
by: TJ | last post by:
Hi I placed one ListView control on a form I would like to check how many items in the ListView control as real-time In other words, whenever total item count of ListView control is chagend, I...
10
by: Rob Nicholson | last post by:
In our application, we've added a bit of JavaScript that updates a title as the user types into a textbox. To trigger this, we patch into the "onkeyup" and "onpaste" events: ...
9
by: foo | last post by:
Hello, What event will fire when a user types data into a field and then the field loses the focus but does not fire when a field is filled programatically? I don't want the event to run when...
5
by: TS | last post by:
Is there a way in debug mode to determine what event caused the postback to occur without having an event handler for that event? thanks
1
by: tomcarr1 | last post by:
What event is triggered in ASP.Net when you close the browser ? What event is normally used to trigger clean up stuff when going from one form to another or leaving the project?
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, When clicking on the top left corner of a datagridview - then entire contents of the datagridview is selected. When clicking on that cell - what event gets triggered/fired? I tried...
7
by: Ross Culver | last post by:
I need to ensure that session variables are removed whenever someone leaves my web site. My understanding is that this should be happening automatically with the session mode set to InProc. But...
3
by: Jason Huang | last post by:
Hi, In my .Net 1.1 C# windows form, I have a DataGrid DG1. The DG1 have a column dc1 which format is TextBox. And I want to check the whave value I have typed in. My question is the new value...
5
by: Dean | last post by:
Hi, I have a table with non-unique identifiers. I need to take all the values with the same ID's and combine them into one field with a semicolon as a seperator. These values may exceed 255...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.