Results 1 to 6 of 6

Thread: Hitting Enter to cause click of button

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 1999
    Posts
    22

    Post

    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.

  2. #2
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Here's how you would do that:

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


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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 1999
    Posts
    22

    Post

    It didn't work. Is there anything else I can do?

  4. #4
    Junior Member
    Join Date
    Jan 2000
    Location
    Colorado, USA
    Posts
    18

    Post

    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!

  5. #5
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    sorry, that was supposed to be vbKeyReturn instead of vbKeyEnter.

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

  6. #6
    Member
    Join Date
    Nov 1999
    Posts
    63

    Post

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width