Link to home
Start Free TrialLog in
Avatar of Merlin_UK
Merlin_UK

asked on

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.
Avatar of simonbennett
simonbennett

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
ASKER CERTIFIED SOLUTION
Avatar of waty
waty
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Merlin_UK

ASKER

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.
Simon
Your idea looks good
I'm testing at the moment
How do I know the Active Contol ??

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
Simon
Your idea looks good
I'm testing at the moment
How do I know the Active Contol ??

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
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 :)