Click to See Complete Forum and Search --> : GotFocus vs LostFocus problem


Cakkie
September 28th, 2001, 07:17 AM
I'm stuck here,

I have some textboxes on a form, and two buttons. One of them is the Cancel button.
Some of the LostFocus events of the textboxes do some checks, and may prompt the user for actions. The problem is when a user presses the cancel button while in one of those textboxes, the lostfocus event fires. What it needs to do is do nothing, since the user pressed cancel. However, the lostfocus event of the textbox fire before the gotfocus event of the command button, so i'm not able to set a flag or something indicating the user is cancelling.

Any thoughts would be welcome

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cimperiali
September 28th, 2001, 07:25 AM
MNot sure about this but, what about using validate event instead of lostfocus?

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Cakkie
September 28th, 2001, 08:01 AM
Same story, validate comes before gotfocus of the button

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cimperiali
September 28th, 2001, 08:04 AM
So, what about do it in the old matter?
Put validate code in click of button event (or its gotfocus)...

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Clearcode
September 28th, 2001, 08:07 AM
..but bizarrely ActiveControl has already changed at that point.


private Sub Text1_LostFocus()

If ActiveControl.Name = "cmdcancel" then
Debug.print "Cancel is next"
else
Debug.print "Cancel isn't next - validating"
End If

End Sub




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.

Cakkie
September 28th, 2001, 08:16 AM
Sorry no can do, cause the lostfocus event must fire if the focus goes to another control, and I can't put the code in every controls gotfocus event.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cakkie
September 28th, 2001, 08:19 AM
Now here's an interesting answer, in fact, a realy valuable answer (Cimp, don't get me wrong, i DO appriciate you answering my questions, only, this one is better :wink , darn, crappy board).

Thanx!

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cimperiali
September 28th, 2001, 08:58 AM
You *must* reside here.
;-)


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater