Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jul 2001
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    enter key code (vb6)

    I am using a textbox to fill in some information, I would like to be able to press enter and have it do something. How di I make it known in my code that 'enter' was pressed? Do i have to use the 'keydown' event for the text box? If so then what?

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: enter key code (vb6)

    Use the KeyPress event of the text box. It has an argument KeyAscii that is the ASCII code for the key pressed by the user. The code for the Enter (Return) key is vbKeyReturn.

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
    MsgBox "You pressed Enter"
    End If
    End Sub

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: enter key code (vb6)

    It depends on the behavior you want from the Enter key. Does Enter mean the operation is finished or merely that you've finished with the textbox? Do you have a default button on your form that will be triggered by the Enter key? You can certainly trap the Enter key as Hans shows, but that may not be the best way to do whatever it is you're trying to accomplish.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    Jul 2001
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: enter key code (vb6)

    Thanks Hans, that is exactly what i needed. Thanks.

Posting Permissions

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