Disabling a Control On Exit

G

Guest

I've created a simulation of an Excel cell in one of my forms, such that the
user can enter a formula, but in leaving it displays the result. This is
implemented by two overlapping controls, txtFormula and txtResult.
txtFormula is bound to an underlying table field, while Result just displays
0 or the result of a Call to the Eval function.

txtResult is set to Enabled and Visible. In the OnGotFocus event, it makes
txtFormula Visible and Enabled, sets the focus there, then disables itself
and makes itself invisible.

I'd like to do just the opposite when I leave txtFormula, but I can't
disable it when it has the focus, which it does when called from the OnExit
or OnLostFocus event. I can do so from the OnEnter or OnGotFocus event of
the next control, which works fine, but the user *could* move backwards or
mouse-click into another control, in which case txtFormula would remain
enabled and visible. The only way I've been able to get it to work is to put
the code in the OnGotFocus event of each enabled control. While this works
now, I'd certainly like to know if there's a better way to do this for next
time. Can anyone tell me how?
 
G

Guest

Sprinks,

One way you could do this is to force the focus to shift to a control that
you choose then disable the control:

Control_B_Name.SetFocus
Control_A_Name.Enabled=False

The only problem with this is obviously the system does not appear to
respond appropriately to the user. A message on the form like "Click ouside
the box to see the result" could help with any potential user complaints
about the system not responding.

Another solution would be to have a "Calculate" button that the user has to
click. Obviously, there is more interaction required by the user to do what
you are already doing automatically, but it solves the focus issue.

HTH
Jason
 
G

Guest

Thanks for taking the time to respond, Jason. Although it seems inelegant, I
think my current solution is friendliest to the user. After years of
complaining that Microsoft and other programmers programmed what was easy for
them, instead of for their users, maybe I should just be happy that it works,
and forget about elegance!

Best regards.
Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top