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!

Setfocus from Valid

Status
Not open for further replies.

phita

Programmer
Jun 8, 2001
82
KE
Hi folks,
I am back again. I want to validate the text that someone enters in a text box. In the valid event of the textbox, I seek whether the code someone has entered exists in a table. If it doesn't exist, I inform the user. Now, I want the cursor to remain in this text box until someone either enters a valid code or leaves the text box empty (necessary for exiting purposes). In the Valid event, I have tried to setfocus to the same textbox (this.setfocus) but it raises an error to the effect that you can't Setfocus from within a Valid event.... What do I do to ensure that the cursor remains in this textbox until someone enters a valid code ?

Thanx,

Peterson.
 
Hi Peterson,

The focus will remain in the textbox if the valid event returns .F.

Jim
 
The other thing you can do is choose where the focus goes in the Valid event by RETURNing a numeric value corresponding to the number of tab stops to advance. So, when the user attempts to move out of the box by any means, the Valid event occurs...returning .F. from the Valid event keeps the focus in the box, and returning 5 would move the focus to the 5th control in the tab order after the one it is leaving.

Note you can also use negative numbers to go backward.
 
1. You cannot set focus to any control from within a valid event.
2. The valid event will retain focus if the return value uis .f... So you should code your valid event .. may be as givn below..

IF EMPTY(This.Value)
RETURN .T.
ELSE
IF This.Value = YourAcceptedValue
RETURN .T.
ELSE
RETURN .f.
ENDIF
ENDIF
RETURN .f.

3. But you can add code in the LOSTFOCUS event to catch up with the exit route.

IF EPTY(This.Value)
ThisForm.RELEASE()
ENDIF


4. But you can put the entire code more conveniently in the LOST FOCUS EVENT.
IF EMPTY(This.Value)
ThisForm.RELEASE()
RETURN .t.
ELSE
IF This.Value = YourAcceptedValue
RETURN .T.
ELSE
RETURN .f.
ENDIF
ENDIF
RETURN .t.

ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
If you return 0 instead of .f. from valid the focus also stays on the object but without the annoying wait window. Of course you then have to supply a message indicating the problem, but I hope you are doing that anyway.

 
Why not let the user exit the textbox, but prevent the user from saving the data, untill the right data has ben entered, or the user has cancelled the operation.

HTH,
Weedz (Wietze Veld) They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best. - Steve McConnell
 
Hi Folks,
Thanx for all your great ideas and suggestions. I really appreciated your help. My forms now look as I had wanted.

Thanx,

Phita.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top