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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble starting a function in keypress event

Status
Not open for further replies.

chiuchimuN

Programmer
Apr 24, 2002
29
0
0
US
I have a search function that finds a listview match from a textbox and scrolls to show this match. The function works fine when placed in a buttons click event but won't start when placed in the textbox keypress event.

Command1_Click()
SearchShow
end sub

Text1_KeyPress(keyascii as integer)
SearchShow
end sub

SearchShow()
Dim S$
S=Text1.Text
//code that searches here(Works fine)
...
end sub

I want this search to behave like the MSDN help index so that is why I want to place function in Keypress.
 
Hi,

In order for the Text1_keypress event to fire, the textbox must be in focus.
Try and put the code in the forms keypress event and set the forms keypreview property to true.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Did'nt work. I'm actually doing this in VBA (Access2000) so maybe this is why I can't trigger function from Keypress.
 
You are using S=Text1.Text
in SearchShow but the entered character will not be put into text1.Text until after keypress and KeyAscii is not 0. Try the change event. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
JohnYingling, you're right about Keypress() Vs change(). The change event worked in VB but not in VBA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top