473,616 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change Enter Key behavior

I have a textbox in a form into which users enter a string to execute a
search. After the user presses Enter, I'd like the focus to go back to the
textbox, but the default behavior of the Enter Key moves the focus to the
next control.

Here's the code:

Private Sub txtFind_KeyDown (KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Call cmdFind_Click
Me!txtFind.SetF ocus ' this does not work
End If
End Sub

Any suggestions welcome.

Thanks in advance!
Nov 13 '05 #1
7 37959
You say that you want the focus to "go back to the textbox". Would you
prefer it never leave the textbox? Should the Enter key do something to the
textbox? Have you looked at Tools|Options|K eyboard Tab|Move after Enter?

--
Wayne Morgan
MS Access MVP
"deko" <ww************ *************** ****@nospam.com > wrote in message
news:QW******** **********@news svr21.news.prod igy.com...
I have a textbox in a form into which users enter a string to execute a
search. After the user presses Enter, I'd like the focus to go back to
the
textbox, but the default behavior of the Enter Key moves the focus to the
next control.

Here's the code:

Private Sub txtFind_KeyDown (KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Call cmdFind_Click
Me!txtFind.SetF ocus ' this does not work
End If
End Sub

Any suggestions welcome.

Thanks in advance!

Nov 13 '05 #2
To change the enter key behavior for the whole database application, from
the Database Window, on the menu Tools | Options | Keyboard, and set the
appropriate action in "Move after Enter". (Note: these are the exact words
in Access 2002, but there may be minor differences in the wording between
Access' versions.)

To change the enter key behavior on a specific control on a form,
right-click, choose Properties, then select Other, and use the property
"Enter Key Behavior".

Larry Linson
Microsoft Access MVP
"deko" <ww************ *************** ****@nospam.com > wrote in message
news:QW******** **********@news svr21.news.prod igy.com...
I have a textbox in a form into which users enter a string to execute a
search. After the user presses Enter, I'd like the focus to go back to the textbox, but the default behavior of the Enter Key moves the focus to the
next control.

Here's the code:

Private Sub txtFind_KeyDown (KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Call cmdFind_Click
Me!txtFind.SetF ocus ' this does not work
End If
End Sub

Any suggestions welcome.

Thanks in advance!

Nov 13 '05 #3
Hi and thanks for the reply.
To change the enter key behavior for the whole database application, from
the Database Window, on the menu Tools | Options | Keyboard, and set the
appropriate action in "Move after Enter". (Note: these are the exact words
in Access 2002, but there may be minor differences in the wording between
Access' versions.)
If I make a change globally, my guess I'll be chasing all kinds of other
issues, so I was hoping to find a way to do it with code.
To change the enter key behavior on a specific control on a form,
right-click, choose Properties, then select Other, and use the property
"Enter Key Behavior".


I tried that, but the only other selection for that property is "New Line in
Field", which causes other problems.

The only other thing I can think of is adding some code to the control that
takes the focus after Enter is pressed - and have that code send the focus
back to the text box. But I may just have to make the global change...

Thanks again for the help.
Nov 13 '05 #4
Thanks for the reply.
You say that you want the focus to "go back to the textbox". Would you
prefer it never leave the textbox? Should the Enter key do something to the textbox? Have you looked at Tools|Options|K eyboard Tab|Move after Enter?


Yes, I know I can make the change globally by changing the "Move after
Enter" option. I was hoping to find a way to resolve this without a global
change (perhaps I should have mentioned that).
Nov 13 '05 #5
On Sat, 30 Oct 2004 21:44:16 GMT, "deko" <ww************ *************** ****@nospam.com > wrote:
I have a textbox in a form into which users enter a string to execute a
search. After the user presses Enter, I'd like the focus to go back to the
textbox, but the default behavior of the Enter Key moves the focus to the
next control.

Here's the code:

Private Sub txtFind_KeyDown (KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Call cmdFind_Click
Me!txtFind.SetF ocus ' this does not work
End If
End Sub

Any suggestions welcome.

Thanks in advance!


If you want the focus to go "back" to the text box, you first have to leave the text box.
Set the focus to another control and then bring it back.

Private Sub txtFind_KeyDown (KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Call cmdFind_Click
Me!SomeOtherCon trol.Setfocus
Me!txtFind.SetF ocus ' this does not work
End If
End Sub
Wayne Gillespie
Gosford NSW Australia
Nov 13 '05 #6
Give this a try:

Private Sub Text0_KeyDown(K eyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then KeyCode = 0
End Sub

--
Wayne Morgan
MS Access MVP
"deko" <ww************ *************** ****@nospam.com > wrote in message
news:nk******** **********@news svr21.news.prod igy.com...
Thanks for the reply.
You say that you want the focus to "go back to the textbox". Would you
prefer it never leave the textbox? Should the Enter key do something to

the
textbox? Have you looked at Tools|Options|K eyboard Tab|Move after Enter?


Yes, I know I can make the change globally by changing the "Move after
Enter" option. I was hoping to find a way to resolve this without a
global
change (perhaps I should have mentioned that).

Nov 13 '05 #7
> Give this a try:
Private Sub Text0_KeyDown(K eyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then KeyCode = 0
End Sub


Thanks - that seems to do the trick.

Here's the complete code:

Private Sub txtFind_KeyDown (KeyCode As Integer, Shift As Integer)
On Error GoTo HandleErr
Dim lngEid As Long
If KeyCode = vbKeyReturn Then
Application.Ech o False
lngEid = Me.Entity_ID
Me.Requery 'this appears to be nec'y - otherwise Me!txtFind is
sometimes Null
If IsNull(Me!txtFi nd) Then GoTo Exit_Here
KeyCode = 0 'not sure if this is best place for this, but it seems
to work
lngCurEid = Me!Entity_ID
Call cmdFind_Click 'go to new entity
If lngCurEid = Me!Entity_ID Then Call GoToEid(lngEid) 'if cd not
find entity, go back to where user was (because Me!Requery has moved form to
first record in database)
End If
Me!txtFind.SetF ocus
Exit_Here:
Application.Ech o True
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogE rr ("frm0"), ("txtFind_KeyDo wn")
End Select
Resume Exit_Here
End Sub

I need both "KeyCode = 0" and "Me!txtFind.Set Focus" because GoToEid has a
SetFocus statement - which is required when GoToEid is called from other
code in the project.
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5652
by: Jeff Gerber | last post by:
/* This test program will give a "Value cannot be null" error. If the lock in this code is removed (or Monitor.Enter()) the program will run as expected. I have found no explaination in lock() or Monitor.Enter() documentation as to why this occurs. I suspect that it is by design of the behind-the-scenes process that lock uses and is not a bug, however, it would be nice if there
1
2195
by: Jeff Gerber | last post by:
/* This test program will give a "Value cannot be null" error. If the lock in this code is removed (or Monitor.Enter()) the program will run as expected. I have found no explaination in lock() or Monitor.Enter() documentation as to why this occurs. I suspect that it is by design of the behind-the-scenes process that lock uses and is not a bug, however, it would be nice if there
7
1339
by: Peter Oliphant | last post by:
I use to make the statement that you could always replace any 'private' or 'public' access with 'public' and the code would still compile. This is no longer the case. It turns out that in /clr it is not allowed (as far as I can tell) to reduce the access of a virtual method defined in a base class. Thus, if one declares a virtual method in a base class as 'protected' and then proceeded to create derived classes with the virtual method...
8
109795
by: rrosebro | last post by:
this work great and stops all enter key presses. now how do i disable the event and fire a tab key event. so if a user presses the enter key i need it to be ignore and tab to the next field. <head> <script type="text/javascript"> function kH(e) { <!-- var pK = document.all? window.event.keyCode:e.which; return pK != 13;
2
1984
by: Andres Romero | last post by:
1. How can I do?, if the user press the Enter key, tranform to the Tab key 2. If someone has used PowerBuilder, there is a way to Post events and functions (PostEvent(eventname) or Object.Post FunctionName/EventName: Adds an event to the end of the event queue of an objec), How can I do it in C#?
2
2310
by: mkppk | last post by:
I have kind of strange change I'd like to make to the sets.Set() intersection() method.. Normally, intersection would return items in both s1 and s2 like with something like this: s1.intersection(s2) I want the item matching to be a bit "looser".. that is, items in s2 that match to just the beginning of items in s1 would be included in the result of intersection().
1
2016
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have a GridView control with a few columns declared directly in the aspx file. I have found that if I remove the HeaderText property from all columns that the GridView handles state completely differently than if any of the columns has a value set for HeaderText. This sounds completely wrong to me. Has anyone ever heard of this? When no columns have a HeaderText, the GridView maintains columns similarly to the old DataGrid. If I...
5
14595
by: Paul Lautman | last post by:
Hi y'all, In IE using this trick onKeyDown="if (window.event.keyCode==13) window.event.keyCode=9; (from http://support.microsoft.com/default.aspx/kb/828907) I can cause an enter key press in an input box to tab to the next field. However in Firefox keyCode is a get only property. How can I make Firefox issue a tab in response to an enter press?
0
973
by: Mozis | last post by:
Greetings, I am using pyuniit for my test cases. I want to change the default behavior to report the errors. I believe it calls TextTestRunner class before calling my test_class(which is child of TestCase class) to set up the framework for error reporting and so on. I can see that it makes the "result" variable of type _TextTestResult class. So while reporting errors, it calls functions of this class.
0
8199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8448
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6097
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4060
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1439
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.