Run Macro On Enter Key In TextBox

  • I have a form, and the form has a textbox. I have a button labeled search, and when it is clicked the macro searches for the information in the text box. How do i make the search action begin when the user press'es the enter key while on the textbox? Thank you!

    "To know the road ahead, ask those coming back.":fatwalk:

  • Re: Textbox To Search When Press Enter


    after the user has entered their data, and they press enter.

    "To know the road ahead, ask those coming back.":fatwalk:

  • Re: Textbox To Search When Press Enter


    Use the exit event for a text box


    Code
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
     'My search code here
    End Sub

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Textbox To Search When Press Enter


    its not working... getting error.


    compile error.
    user-defined type not defined..


    highlighting

    Code
    Private Sub PolNo_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    [hr]*[/hr] Auto Merged Post;[dl]*[/dl]solved.. thanks for trying to help..


    Code
    Private Sub PolNo_KeyPress(KeyAscii As Integer)
        If (KeyAscii = 13) Then 'Keyascii 13 = Enter key
        Call Command1_Click
        End If
    End Sub

    "To know the road ahead, ask those coming back.":fatwalk:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!