PDA

Click to See Complete Forum and Search --> : Hitting Enter to cause click of button


Playmaker
Jan 12th, 2000, 05:05 AM
I have a login screen with just two fields, username and password, and two command buttons, login and cancel. After a user puts in the password, I want them just to hit <Enter> and it automatically login, just as if they had clicked the login command. Is there a way to do this?

Thanks.

Gimpster
Jan 12th, 2000, 05:15 AM
Here's how you would do that:

Private Sub Text1_KeyPress()
If KeyAscii = vbKeyEnter Then
KeyAscii = 0
Command1.Value = True
End Sub

------------------
Ryan

Playmaker
Jan 12th, 2000, 06:09 AM
It didn't work. Is there anything else I can do?

Carroll
Jan 12th, 2000, 06:30 AM
I tested this and the 'vbenter' did not work for me either so I replaced it with 13 which is the keycode for 'enter'. This worked for me. Give it a shot.

If KeyAscii = 13 Then
KeyAscii = 0
Command1.Value = True
End If

Good Luck!

Gimpster
Jan 12th, 2000, 06:48 AM
sorry, that was supposed to be vbKeyReturn instead of vbKeyEnter.

------------------
Ryan

Gerald
Jan 12th, 2000, 09:10 AM
No need to mess around with the KeyPress event. Just set the Default property of your login command button to True and you're all set. You can also set the Cancel property of your cancel button to True and when the user presses the escape key the cancel button click event will be fired.

Gerald


[This message has been edited by Gerald (edited 01-12-2000).]