Event query

J_Orrell

Registered User.
Local time
Today, 05:25
Joined
May 17, 2004
Messages
55
Hi guys...another query to test you all :) What event happens when someone is typing text in a textbox and then they hit <Enter>? The textbox is set to receive a single line of text, so pressing <Enter> causes the textbox to loose focus. Obviously the 'Lost Focus' event happens but I want to specifically test if <Enter> has been pressed. Basically the textbox in question is a password-box and if the user hits <Enter> I want to invoke the 'log in' procedure but I'm stuck with what event to test for.
 
HI John I've previously tried that but it isn't invoked when the user hits <Enter>

If there isn't a specific event, maybe I could use the Lost Focus event and test to see if the <Enter> key has been pressed, but I'm not sure how to test for specific keypresses: VB doesn't seem to have the age-old favourite 'Inkey' or 'Inkey$'. Does it have an equivalent?
 
It is:
Code:
Private Sub txtName_KeyPress(KeyAscii As Integer)

    Select Case KeyAscii
    Case 13 ' Use pressed enter
        MsgBox "User pressed : enter"
    Case Else
        MsgBox "User pressed :" & Chr(KeyAscii)
    End Select
        
End Sub
even when you press the control or alt keys, it is invoked.

The Inkey$ statement in GWBasic and Basica and events in Office such as KeyPressed are mostly the same.
 
I've tried that but if I put it in the textbox's KeyPress event it still doesn't detect if <Enter> was pressed, because the textbox looses focus before it invokes the KeyPress event.

However...

I think I may have solved it: when the textbox looses focus, focus is transferred to the form's 'Log In' button. If I test the button's KeyPress event - not the textbox's - I suspect that will work...I'll let you know
 
Last edited:
Any luck with this? I'm working on the same thing. I found I could change the <enter> key's behavior under the "Other" tab to New Line In Field and it works, however it appears to be adding the enter character to the password, thus it's wrong (if they mistype it once).
 
I removed my Log In button from being a tabstop and it now works...Don't know if it'll help you or not, but it's fine for me! Good luck!
 

Users who are viewing this thread

Back
Top Bottom