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!

Making Lostfocus Not Run

Status
Not open for further replies.

Serincino

Programmer
Jun 13, 2003
61
US
I have a program where the user enters in an account number and the rest of the data is filled into the form. If it is an incorrect account number the users is informed with a pop-up message and focus is returned to the account field. If they enter 0 in the textbox, then focus is automatically sent to the exit button. My problem is that if they enter an incorrect account number, or enter in a correct one then click on the exit button the code is still run (some accounts have multiple entries and a browse window pops up for them to select the correct one) I do not wish for this to run (LostFocus) if they click on exit. Any ideas? I'm been researching and trying to figure out the answer for over a day now. Thanks in advance.

-Serincino
 
I would do it in the Keypress event.

The code to gather the data.

In the keypress event, checkfor the enter key or the tab key!

This way, the lostfocus won't fire!!!

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Serincino,

check if you have TabStop property set to .T., set it to .F. if not, and see if this would help.

I also run into this kind of problem sometimes, and setiing TabStop to False usually helps.


Regards,

Ilya
 
TabStop didn't fix the issue. The way I see it is I need a way to find where the focus is shifting to to place a condition in the LOSTFOCUS area that if such condition is to the exit button, RETURN, ELSE so everything.
Thanks for the ideas so far folks.

-Serincino
 
Also changing it to a keypress event would defeat my purpose, I want all the other stuff to run, unless the exit button is pressed or focus is shifted to that.
 
Serincino,

I think what you are proposing is not possible (the way you have it laid out)...the lostfocus event fires prior to the clicked control receiving focus...so in a sense VFP doesn't know that the Exit button is being clicked yet. There something you could try if you really need it to work this way, but none of the ideas I can think of are good solutions...in the Exit button's Mousedown event you may be able to set a variable (doesn't handle hotkeys though)... and just because the user mousedowned it doesn't necessarily mean that the mouseup will happen over that control so it may not be an actual click... this may work for you, but I really think you should rethink the design and the placement of your code in that control's lostfocus event...this may be one of those times where you have to bite the bullet and place that code in a for method and call it from every control's gotfocus event then leave the call out of the gotfocus of the Exit button or something. Is that very maintainable??? NO, but it is workable which beats what you have now. There may be an even better way to handle this, my best advice to you is to look at how you can get rid of your reliance on that lostfocus event, figure that out and you'll be home free.

Slighthaze = NULL
 
Serincino -

Wouldn't the valid event be a good place to evaluate the account number. That way focus won't leave the account number until you are ready.

Steve
 
Serincino,

you might wanna try this:

check the account No. entry in your TextBox.KeyPress procedure; if nKeyCode = 13 (user hit Enter) do all your checks and validations;

do the same in cmdExit.Click procedure (you might run it like TextBox.KeyPress(13)).

See if it's what you need.


Regards,

Ilya
 
Thanks for all the help guys. I've did a bit of a work around, still not exactly the effect I was looking for though. What I really was looking for was how to detect what control was being selected before LostFocus would run, that way I could see if it was the exit button, and if it was then enclose the code I didn't want to run in an if statement.

Again thanks for all the help,

Serincino
 
Serincino,

You can also disable your exit button at gotfocus on account field then enabled it after validation of correct entry.

Peping
 
As I understand the issue, you want the program to know when the user has pressed the exit button, and to also know the object that previously had the focus. I have accomplished this in the past by initializing a global variable in the init event of the form (cPrevFocus).

In the GotFocus event of each object that I'm concerned about, I set the value of cPrevFocus = This.Name. In a circumstance such as the one you describe, I would not put anything in the LostFocus event, but would set up a Case structure or series of IF statements in the GotFocus event (in your case the Exit Button) to determine the appropriate actions such as checking the previous object for valid values.

It is probably better coding practice to use the Valid Event to check for appropriate values, but in those intances where a client wants to get rid of the annoying messages everytime they hit the exit button (they know the value is wrong but just want to leave) this has worked for me. And I've also found other good reasons for knowing what the previous object was.

CDavis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top