PDA

View Full Version : Solved: User Form question



JKwan
03-02-2009, 09:07 AM
I have a Login Form where it has UserName, Password and an OK button. What I wanted to do is that when a user filled in the UserName and Password, one can either hit the ENTER key or the OK button to exit the form. I am having difficulty trapping the ENTER key. I tried the Form Key down and Press event (I guess the form does not have the focus), no avail. I tried the AfterUpdate event within my Password textbox, it "trapped" it but the form does not unload. What am I missing?

Thanks.

Kenneth Hobs
03-02-2009, 09:10 AM
In your button's click event, Unload Me. As for the Enter key, you want it to exit from the password's textbox control?

Bob Phillips
03-02-2009, 09:11 AM
A form button has a default property, set this to True for your button, that means it responds to Enter a well as a click.

lucas
03-02-2009, 09:19 AM
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = 13 Then
KeyCode = 0
Sheet1.Range("A65536").End(xlUp).Offset(1, 0) = Me.TextBox1.Value
Unload Me
End If
End Sub

JKwan
03-02-2009, 09:22 AM
Thank you all for answering my question. XLD's is the simplest solution