How can I run code on Enter press in a textbox?

Posted on 2011-10-17
Last Modified: 2012-05-12
I have a text box called TxtSearch and a command button. A search tern is entered in the text box and then the user clicks the command button. How can I have the user enter the search term and just hit enter to run the code?
Question by:seanlhall
    LVL 75

    Accepted Solution

    Put the code from the command button in the AfterUpdate event of the search text box.

    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)

    Private Sub YourSearchTextBoxName_AfterUpdate
       ' your search code here
    End Sub

    LVL 61

    Expert Comment

    Have you tried using the AfterUpdate event of the textbox?

    I believe that gets fired when the Enter Key is hit, as long as the textbox's Enter Key behavior property is set to 'Normal', not 'New Line In Field'.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now