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

test for lostfocus reason ?

Status
Not open for further replies.

mallee

Programmer
Nov 7, 2000
116
Hello all you experts.
Your help has been immense and I thank you all.

I have a form with textboxes and comand buttons. If a textbox has focus and is waiting for input, is there a way for me to see if the user clicked on a command button, causing the current textbox to losefocus ? (I have some code in the textbox valid event that I don't want to fire if a command has been clicked)

Thanks agin.
 
Mallee,
There is a LostFocus event which fires any time an object, well, losses focus. I suspect you could use something like lcLastValue = Inkey() in your lost focus routine, to set a value, to .T. if it was a mouse click. (I don't remember the mouse click value off the top of my head, but use VFP Help to get a list of values. (Do help on INKEY, I think that will tell you values for Mouse Click). You could then decide to do, or not do, something right in your LostFocus event, instead of your VALID, since I'm not 100% certain which event will fire first. But, if you put all the code in LostFocus, it won't matter.
Best Regards,
Scott

Please let me know if this has helped [hammer]
 
I would say it mainly depends on exactly what your VALID event is doing. Perhaps this is your scenario:

1) Valid event validates the data entered and doesn't allow you to leave the field if it has bad data.

2) You want VFP to skip the validation code if the user is clicking on the CANCEL button

There isn't a simple way to know exactly what caused the attempted loss of focus. I'm not sure it's entirely possible. If your situation matches the one above, consider removing all validation code from VALID events and put it all in one Form method. Then, in your SAVE button, call the Form.ValidateData method and only proceed if it returns .T.

Ian
 
Thanks guys, Scotts suggestion about inkey works great.
I was filling some other textboxes in valid event of first textbox and did not want this to happen if user clicked my
Post command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top