Lost Focus Problem with Default and Cancel Properties

I have some Text controls with code in the LostFocus Events for them and these work fine until the user Presses ENTER or ESCAPE. I know the reason my code stops working is becoause the ENTER and ESCAPE keys are taking effect without a LostFocus Event being triggered for the Text Boxes.
Does anyone know how to stop this happening.
I do need to have the Default and Cancel properties set for the 2 Command Buttons as well as the LostFocus code.
Merlin_UKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

simonbennettCommented:
Can you not check on the forms KeyPress event to check for enter or escape, get the activecontrol and then runs its lost focus code?

HTH

Simon
0
watyCommented:
You have one command buton with the default property set to true
and another (or the same) with the cancel property set to true
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Merlin_UKAuthor Commented:
Yes Waty
My original question didn;'t stress that I need 2 command buttons, on with default proprty set to true and one with Cancel property set to true.
because of this, the escape and enter keys kick in BEFORE the loastfocus events of the other controls.
I would still like to have the Default and CAncel properties set but I must have the LostFocus working every time.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Merlin_UKAuthor Commented:
Simon
Your idea looks good
I'm testing at the moment
How do I know the Active Contol ??

0
watyCommented:
To know the active control :
screen.activeControl

But I suggest that you remove those Default and Cancel property and in each lostfocus event, if the user has pressed enter or Escape, call explicitelly the click event of you 2 buttons
0
Merlin_UKAuthor Commented:
Simon
Your idea looks good
I'm testing at the moment
How do I know the Active Contol ??

0
Merlin_UKAuthor Commented:
Waty
That's what I was thinking of doing, trouble is I know it's bad form, but I have 15 Text Boxes all with different names ........
Guess I'll have to re-name them in a control array like I should have done in the first place
Thanks for your help mate
0
watyCommented:
Some tips,

I use a lot the scree.activecontrol

like in the gotfocus event to select all the text, so I simply copy & paste the code from 1 gotfocus to another :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.