• enter key code (vb6)

    Author
    Topic
    #375195

    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

    Viewing 1 reply thread
    Author
    Replies
    • #609574

      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

      • #609697

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

    • #609622

      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.

    Viewing 1 reply thread
    Reply To: enter key code (vb6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: