You might need to set the form property KeyPreview on your form to True to catch these key presses.
:)
Main Topics
Browse All TopicsI have a VB 6 application in which I have several text boxes on a form. When the user types in a number in the first text box and presses the Enter key, I want the application to set focus to the second text box, etc.
I have done this in previous application to speed up data entry, but now when I try it, it does not seem to work. Below is the code I am using.
Private Sub txtContract_Labor_KeyPress
If KeyAscii = 13 Then 'User pressed the Enter key
txtContract_Materials.SetF
End If
End Sub
This code below does not even fire off when the enter key is pressed:
Private Sub txtContract_Labor_KeyDown(
MsgBox KeyCode
End Sub
Any ideas why it does not work? Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks everyone for the input. I entered the KeyPress code above and it does get triggered when all keys are pressed "except" the Enter key. (The shift, cntr, and alt keys also do not trigger the event, but I only care about knowing when the Enter key is pressed.)
I don't get this as I have used this logic before and it has worked perfectly. The text box is on a frame which is on the form but that should not matter as the text box does have focus. I also did confirm the name of the text box by double clicking in design view mode and it is the correct name.
I have set a breakpoint at the KeyPress line and it is not triggered when the Enter key is pressed. It is only triggered when the numeric and alpha keys along with the + and - signs are pressed.
Any ideas? Thanks.
1. The Enter key is not broken. I tested it in another applicaton I wrote and it works the way it is suppose to.
2. I use the term Enter and that is what is printed on the key.
3. Good question about the intrinsic one or one from Forms 2.0 or rtf etc. It is the intrinsic one. In fact, I copied a new textbox to the form and tried it and it does not work either. Very strange.
4. Below are the settings of the textbox:
txtContract_Labor TextBox
Appearance Flat
BorderStyle 1-Fixed Single
HideSelection True
CausesValidation True
4. Below are the settings of the textbox:
txtContract_Labor TextBox
Appearance Flat
BorderStyle 1-Fixed Single
HideSelection True
CausesValidation True
Enabled True
Locked False
MaxLength 20
MultiLine False
ScrollBars 0-None
TabIndex 41
TabStop True
Visible True
Name txtContract_Labor
Alignment 1-Right Justify
HelpContextID 0
Index
MouseIcon (None)
MousePointer 0-Default
PasswordChar
Tag
Text
ToolTipText
WhatThisHelpID 0
I did not list all of the properties.
Thanks for the help
I found part of the problem. I have on the form some command buttons. One of them (the "Add" button) I had set the Default property to True. When I changed it to False, then when I press the Enter key on the txtContract_Labor control, the KeyPress event does work correctly.
Possibly contributing further to the problem is the fact that I have set up some automatic help text that triggers whenever the cursor moves over any control on the form. I user each control's MouseMove event. That might be causing the txtControl_Labor text box to loose control? That does not seem to be happening but I can't figure out why setting the Default property on the "Add" command button from True to False allows the KeyPress event to work on the text box.
Thanks for the input.
I don't get that. Does setting the command button's default property from False to True mean that anytime the enter key is pressed anywhere on the form, the command button is triggered?
that's true
try setting a messagebox in the command_click of that particular commandbutton and is should fire
in fact this is the same with the cancel property, but then for the escape key
Business Accounts
Answer for Membership
by: Idle_MindPosted on 2006-03-20 at 19:54:19ID: 16243702
It works fine for me:
(KeyAscii As Integer)
Private Sub txtContract_Labor_KeyPress
If KeyAscii = 13 Then
KeyAscii = 0
SendKeys "{TAB}"
End If
End Sub