Results 1 to 5 of 5

press enter when in search box to display results

  1. #1
    neill_long is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    7

    press enter when in search box to display results

    Hi

    I have a search box within a form that searches multiple fields, I have set it up to search when the search button is clicked. But I would also like it to search when the user presses enter. I have been trying to add code but it isn't working and hope to get some help please.

    I have added the following with in the KeyDown event:

    Private Sub txtsearch_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then


    Me.Refresh
    but_Enter_Click
    KeyCode = 0
    End If
    End Sub


    I don't think it is liking the but_Enter_Click.

    I'm a beginner when it comes to code so any help or advice would be great.

    thanks
    Alistair

  2. #2
    Minty is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    495
    Move the code for your search button into a private sub in the form called Private Sub SearchText()
    Then on both your button click event and your enter key detection event you can simply use

    SearchText
    Please use the star below the post to say thanks if we have helped !

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    2,740
    Will this work for you, in your situation?

    In Form Design View

    1. Select your Command Button
    2. Go to Properties - Other
    3. Change the Default Property to Yes


    Now anytime you hit the Enter/Return Key this button's code will fire.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    neill_long is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    7
    Thanks for the replies, went with your suggestion Linq and works great.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    2,740
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-05-2015, 02:49 PM
  2. Replies: 5
    Last Post: 03-02-2014, 11:37 AM
  3. When press enter key will log in
    By dododo in forum Forms
    Replies: 1
    Last Post: 07-17-2013, 09:58 PM
  4. Replies: 5
    Last Post: 01-03-2013, 12:38 PM
  5. Replies: 1
    Last Post: 07-21-2011, 12:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums