Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Event Text Field

Status
Not open for further replies.

Tommy408

Programmer
Apr 30, 2006
53
US
Is it possible to catch the value in a text field right after every key entered into the text field?

It seems that the event for example, On Key Up, is too slow to and the text field gives me a null.
 
I've tried all the events that would instantly call a Procedure.

Before Update
After Update
On Change
On Key Down
On Key Up
On Key Press

I don't think other events would produce the instant procedure call like I want. Events like On Click for example would not be the idea. The idea is to catch the data after the key is up. But it can't catch the text field value unless I change focus in and out of that text field.
I'm sure there's a trick to this.
 
Can you say what you wish to do? You should not have to change focus to find out what has been typed - the text property of a textbox contains that.
 
When the user press a key for example, "d", a message box appears and say, "you have press the letter d."
Simple as that. But the procedure through event can't get the value fast enough so it gives a null value. THe message box would be "you have press the letter "NULL" ...just an example.
 
This works for me:
Code:
Private Sub txtText_KeyPress(KeyAscii As Integer)
strKeys = strKeys & Chr(KeyAscii)
MsgBox "You have pressed " & strKeys
End Sub
 
Oops, I should have said that strKeys is declared at module level.
 
That code retrieve key pressed. It doesn't read from the text field.
My original problem as the title said...I need to retrieve the value in the text field with on event. I can see what I type in the text field, but the computer doens't see it with on event.

 
In the Change event procedure of the TextBox play with the Text (not Value) property of this control.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I think I mentioned the text property in my second post:
the text property of a textbox contains that
 
You're not grasping my first post.

"Is it possible to catch the value in a text field right after every key entered into the text field?
It seems that the event for example, On Key Up, is too slow to and the text field gives me a null."

The only way someone know, is if they open up access, run the code. Otherwise plainly saying it won't work.

Let me elaborate.
When you enter a letter "a" in the text field, ALL the events so far, MsgBox Me![TxtField].Text will output Null, the next letter you press "b", MsgBox Me![TxtField].Text will output "a"
Huge problem.
 
WOOT
Thanks for your help Remou and PHV.

Remou said to use Text property.
PHV said to use Change event.

Together they work.

Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top