Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 12-07-2018, 09:10 AM   #1
sumdumgai
Newly Registered User
 
Join Date: Jul 2007
Posts: 324
Thanks: 75
Thanked 0 Times in 0 Posts
sumdumgai is on a distinguished road
Start search with 'Enter' key

Need some help, please. I have a name lookup form with several search argument boxes; e.g., address, state, zip, etc. I do not want to initiate the search program with a 'Search' button, or when the user enters an argument and then tabs to the next search box. I would like to allow the user to input as many search arguments as he/she wants on the form, and then hit the 'Enter' key to begin the search.
Thanks for any help.

sumdumgai is offline   Reply With Quote
Old 12-07-2018, 09:42 AM   #2
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 9,557
Thanks: 369
Thanked 785 Times in 750 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Start search with 'Enter' key

What about:-

Code:
Private Sub txtPassword_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Me.Refresh
but_Enter_Click
KeyCode = 0
End If
End Sub

Found HERE:-
https://forums.windowssecrets.com/sh...d-(Access-2000)
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)

Last edited by Uncle Gizmo; 12-07-2018 at 09:47 AM. Reason: copied wrong one!
Uncle Gizmo is offline   Reply With Quote
The Following User Says Thank You to Uncle Gizmo For This Useful Post:
sumdumgai (12-07-2018)
Old 12-07-2018, 09:45 AM   #3
Micron
Newly Registered User
 
Join Date: Oct 2018
Location: Ontario, Canada
Posts: 66
Thanks: 0
Thanked 10 Times in 9 Posts
Micron is on a distinguished road
Re: Start search with 'Enter' key

On form property sheet, set KeyPreview property to Yes, then the form should get any keypress event before any control keypress event, assuming you have any. Try KeyPress event for the form to launch your search, as in If KeyAscii = vbKeyReturn Then...
Hopefully you are coding so that if some controls don't have data, the search will work properly if it's allowed to run.

Micron is offline   Reply With Quote
The Following User Says Thank You to Micron For This Useful Post:
sumdumgai (12-07-2018)
Old 12-07-2018, 09:53 AM   #4
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 9,557
Thanks: 369
Thanked 785 Times in 750 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Start search with 'Enter' key

If you need to build a search form, see my YouTube videos HERE:-

http://www.niftyaccess.com/building-search-criteria/

The Search Form is available (for a limited time ) for free from here:-

https://sellfy.com/p/erBU/

Use Coupon Code:- "Contact me"
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)

Last edited by Uncle Gizmo; 12-10-2018 at 02:38 AM. Reason: removed coupon code
Uncle Gizmo is offline   Reply With Quote
Old 12-07-2018, 10:02 AM   #5
sumdumgai
Newly Registered User
 
Join Date: Jul 2007
Posts: 324
Thanks: 75
Thanked 0 Times in 0 Posts
sumdumgai is on a distinguished road
Re: Start search with 'Enter' key

This is what I found elsewhere:
Code:
Private Sub fName_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Me.Refresh
        MsgBox 1
        runSearch
        KeyCode = 0
    End If
End Sub

It's what Uncle suggested and seems to work. Do I still need to set KeyPreview to yes?
sumdumgai is offline   Reply With Quote
Old 12-07-2018, 10:27 AM   #6
AccessBlaster
.
 
Join Date: May 2010
Posts: 897
Thanks: 20
Thanked 239 Times in 228 Posts
AccessBlaster will become famous soon enough AccessBlaster will become famous soon enough
Re: Start search with 'Enter' key

Quote:
Originally Posted by sumdumgai View Post
Need some help, please. I have a name lookup form with several search argument boxes; e.g., address, state, zip, etc. I do not want to initiate the search program with a 'Search' button, or when the user enters an argument and then tabs to the next search box. I would like to allow the user to input as many search arguments as he/she wants on the form, and then hit the 'Enter' key to begin the search.
Thanks for any help.
Maybe try this, no code required.
Attached Images
File Type: jpg Capture.JPG (97.8 KB, 93 views)
AccessBlaster is offline   Reply With Quote
The Following User Says Thank You to AccessBlaster For This Useful Post:
sumdumgai (12-07-2018)
Old 12-07-2018, 10:49 AM   #7
Micron
Newly Registered User
 
Join Date: Oct 2018
Location: Ontario, Canada
Posts: 66
Thanks: 0
Thanked 10 Times in 9 Posts
Micron is on a distinguished road
Re: Start search with 'Enter' key

Default will only work if the button has the focus. Since user is entering data, I suspect the last control edited will have the focus. User would have to give or code programmatically set the focus after the last control is edited, which won't work either if the user can/will edit controls in any random order.

You don't need preview on form, unless as noted, any form controls also have key events. Even then, it would depend on which you want to have priority. If you set it and forget and put key events on a control later, the form key event will fire first, which may or not be what you want, such as if the key event was to close the form. That's not something I'd ever do, but am just throwing it out there for an example.


Last edited by Micron; 12-07-2018 at 10:55 AM. Reason: clarification
Micron is offline   Reply With Quote
Old 12-07-2018, 11:24 AM   #8
sumdumgai
Newly Registered User
 
Join Date: Jul 2007
Posts: 324
Thanks: 75
Thanked 0 Times in 0 Posts
sumdumgai is on a distinguished road
Re: Start search with 'Enter' key

Zip code field is last search box on form. I used this:
Code:
Private Sub Zip_LostFocus()
    runSearch
End Sub

so if the user enters 'Zip' box and tabs out, whether entering data or not, the search starts.

Everything seems to work.


Thanks to all.
sumdumgai is offline   Reply With Quote
Old 12-07-2018, 12:50 PM   #9
AccessBlaster
.
 
Join Date: May 2010
Posts: 897
Thanks: 20
Thanked 239 Times in 228 Posts
AccessBlaster will become famous soon enough AccessBlaster will become famous soon enough
Re: Start search with 'Enter' key

Quote:
Originally Posted by Micron View Post
Default will only work if the button has the focus.
Huh, mine works fine without setting any focus. The point of the default action set to "yes" on any button is to tell access you want that button to simulate the enter key.

I could be wrong.

Last edited by AccessBlaster; 12-07-2018 at 01:00 PM.
AccessBlaster is offline   Reply With Quote
Old 12-07-2018, 02:19 PM   #10
Micron
Newly Registered User
 
Join Date: Oct 2018
Location: Ontario, Canada
Posts: 66
Thanks: 0
Thanked 10 Times in 9 Posts
Micron is on a distinguished road
Re: Start search with 'Enter' key

Quote:
Originally Posted by AccessBlaster View Post
Huh, mine works fine without setting any focus. The point of the default action set to "yes" on any button is to tell access you want that button to simulate the enter key.
I could be wrong.
Doesn't seem so. I was going by some hap-hazzard test I guess. Repeating it on another form is giving different results. While the form events do run first if key preview is Yes, only if the focus is on some other button does your suggestion not work. Thanks for the lesson!
Micron is offline   Reply With Quote
Old 12-07-2018, 02:52 PM   #11
AccessBlaster
.
 
Join Date: May 2010
Posts: 897
Thanks: 20
Thanked 239 Times in 228 Posts
AccessBlaster will become famous soon enough AccessBlaster will become famous soon enough
Re: Start search with 'Enter' key

Quote:
Originally Posted by Micron View Post
Doesn't seem so. I was going by some hap-hazzard test I guess. Repeating it on another form is giving different results. While the form events do run first if key preview is Yes, only if the focus is on some other button does your suggestion not work. Thanks for the lesson!
Ah, after rereading your answer I see where we differ. I am only speaking of the button behavior (properties). I see now you are speaking of the form properties. Sorry bout that.

I have never used the key preview event, in fact I had to look it up.

Thanks

AccessBlaster is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Is it possible to force a query to start table search at end? sumdumgai Queries 26 01-26-2014 06:14 PM
Enter Start & End Date error noosalucy Reports 1 11-03-2013 08:01 PM
Search for dates between start and end columns 01706 Queries 1 04-11-2010 05:33 PM
Enter key search IpeXeuS Forms 3 09-19-2007 02:57 PM
Select start and end dates AND press Enter for all macherie Queries 9 11-13-2003 05:29 PM




All times are GMT -8. The time now is 05:53 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World