Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    RETURN KEY VALUE? (Excel 2003)

    Hi all,

    I read the documentation regarding sending KeyANSI for the KeyPress Event.....my question is this,

    I have a textbox on a form, that I would like to use the ENTER key as the trigger for an event, is this possible?

    Thanks,
    Darryl.

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

    Re: RETURN KEY VALUE? (Excel 2003)

    To trap the Enter key, you must use the KeyDown event, not the KeyPress event. For example:

    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyReturn Then
    ' Your code goes here
    ...
    ' If you want to disable the normal action of Enter
    KeyCode = 0
    End If
    End Sub

    By default, the focus will move to the next control if you press Enter; to disable this, you can change the KeyCode argument to 0.

    BTW, if you want the Enter key to activate a command button, set the Default property of that command button to True. No code needed.

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: RETURN KEY VALUE? (Excel 2003)

    Thanks Hans

Posting Permissions

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