Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter key won't move cursor between fields

Status
Not open for further replies.

procom

Programmer
Jan 28, 2001
4
US
I have a form which will not allow the [Enter] key to move the cursor from one field to the next. All the command buttons on the form respond to the [Enter] key and the valid statements on each control respond to the Enter key but the cursor will not move unless I use the Tab key.
 
Hi!

Try following:
Set form's KeyPreview property to .T.
In the KeyPress event put following code:
lparameters nKeyCode, nShiftAltCtrl
if nKeyCode = 13 && Enter key
keyboard '{TAB}'
nodefault
endif


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
I tried setting the keypress event, but when I execute the code, the cursor will move from field to field when the Enter key is tapped, but the command buttons no longer execute since the Enter key now is interpreted as a Tab.
 
Well, refined code for you (with checking for command buttons):

lparameters nKeyCode, nShiftAltCtrl
local loActiveControl
m.loActiveControl = thisform.ActiveControl
if type("m.loActiveControl") == "O" AND m.loActiveControl.BaseClass == 'Commandbutton'
if nKeyCode = 13 && Enter key
keyboard '{TAB}'
nodefault
endif
endif
m.loActiveControl = ""

Just get a general idea. Seems you forget that you can modify this code at will ;)


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Thanks for the help. I found I could also solve the problem by inserting a KEYBOARD 'TAB' statement into the valid statement of each field.
 
Don't do this, use KeyPress of each control. When you will do this in valid event, than check lastkey() for which key pressed by user to change focus. I afraid otherwise it will not work when user will change focus, for example, by mouse clicks.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
1. JUST CHECK THE TAB ORDER.
2. IS THE KEYPRESS EVENT CONTAIN - NODEFAULT EXPLICIT OR INHERITED?
IT IS RARE, HOW THE ENTER KEY CANNOT GO TO NEXT TAB ORDER - UNLESS INTENTIONALY DONE SO?

RAMANI
 
I had the same problem in a VFP5 form. Turns out a 'setfocus' command in the form's init event was causing the problem. I moved the code from the form's 'INIT' event to its 'ACTIVATE' event. After that change, the enter key moved the focus from field to field with no problem. Hope this helps.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top