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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dont want to leave textbox

Status
Not open for further replies.

DarrenWard

IS-IT--Management
Feb 15, 2002
217
GB
I have a text box that when I press enter it does some validation in the keypress event, if a condition is met it shows a message and then I want the textbox to retain the focus.

I have tried the valid event and setting the setfocus, but the event still moves focus to the next control, I know it's something simple but I can find it in the help files.

Dazz (Like Harry Potter's schooling, I can't do anything without a spell checker)
 
Here is one way of doing it:
Create a new property on your form (Called RetainFocus and leave it logical)
In the KeyPress event determine if you want to keep the focus:
Code:
IF nKeyCode = "whatever"
  thisform.RetainFocus = .t.
ELSE
   thisform.RetainFocus = .F.
ENDIF
And in the LostFocus check the value of RetainFocus:
Code:
IF thisform.RetainFocus = .t.
  NODEFAULT
ENDIF






 
How about return a false value in the valid event to prevent user leaving the textbox.
Note that return a true value will let the focus go to next control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top