Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: run code when enter is pressed in userform.

  1. #1
    Board Regular
    Join Date
    Jan 2008
    Posts
    304
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default run code when enter is pressed in userform.

    Is there a way that will run the code from a button when the enter key is pressed. Currently the enter key moves to the next text box in the user form.

  2. #2
    Board Regular
    Join Date
    Jun 2002
    Posts
    2,128
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: run code when enter is pressed in userform.

    Use the textbox's keydown procedure:

    Code:
    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    
        If KeyCode = vbKeyReturn Then
            CommandButton1_Click
        End If
    
    End Sub

  3. #3
    Board Regular
    Join Date
    Jan 2008
    Posts
    304
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: run code when enter is pressed in userform.

    Thanks worked like a charm.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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