setfocus doesn't work

deadfish

Registered User.
Local time
Tomorrow, 01:07
Joined
Apr 8, 2004
Messages
10
I have a form that contains a textbox. The program insert record when user input text into the textbox and then press enter. I want to make the focus stay at the textbox and wait for the second input from the user. I have tried to put setfocus at the afterupdate event of the textbox but failed. How to archieve this? Thanks in advance.
 
You could remove all the tab stops from all the other controls on the form except the one for the control you want the focus to remain on.
hth
Chris
 
The enter key is probably being processed after the after update event occurs.
So after all your code runs and sets the focus where you want it, then the enter key is processed and the focus is moved to the next field.

Try using the OnKeyDown event to 'capture' the enter key and then cancel the event, thus retaining the focus. The only problem is that the update event will not occur because the enter key has been canceled - so you will have to manually simulate this.

If you go this rout, you will also need to trap the TAB key.
 

Users who are viewing this thread

Back
Top Bottom