Enter Key problem (1 Viewer)

sstreet

Access Demon
Local time
Today, 14:34
Joined
Dec 5, 2002
Messages
50
I am using the keypress event of a textbox to run some code instead of having to click a button. The problem I am getting is that when the enter key is pressed, the control simply moves to another text box.

I believe that this has something to do with the Enter key behaviour event, but I have had no luck turning this off.

Thanks for your help
 

samehkh

Registered User.
Local time
Today, 09:34
Joined
Aug 11, 2003
Messages
63
Did you try checking the keycode value for [ENTER] ?
by using if (keycode=.....) then
cancel
......run your code
move focus to the next control

end if
 

sstreet

Access Demon
Local time
Today, 14:34
Joined
Dec 5, 2002
Messages
50
I have tried that, but it still does the same thing.
There must be some way to stop the enter key from moving focus to the next tab stop?
 

Fizzio

Chief Torturer
Local time
Today, 14:34
Joined
Feb 21, 2002
Messages
1,885
You cannot trap the enter by using Keypress, however, as samehkh has suggested, you can trap the Keycode but by using the KeyDown Event.

eg

Code:
Sub YourControl_KeyDown(blah blah)
if Keycode = vbreturn then
keycode = 0
'Run your code here
end if
end sub

If you want this behaviour by default for all your controls, set the KeyPreview of the form to yes, and use the KeyDown event of the form.

hth
 

Users who are viewing this thread

Top Bottom