Mark
asked on
How to determine which control has focus
How can I determine which control currently has focus on a form?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Screen.ActiveControl.Name or Me.ActiveControl.Name both work -- sort of. They work on the main form. However, I have a subform. When I click a button, the button event requeries the subform to refresh its content. The subform's Form_Current function calls a subroutine on the parent form which may try to disable the very button I clicked -- error -- it has focus. The problem with the solutions givein is that parent form must have control othwise I get an error using these.
Suggestions?
Suggestions?
This is difficult, Buttons, toolbars etc tend to "keep" the focus nomatter what you do from code. The solution I normally end up using is to let the button set a timer on the form and from the timer code set focus on some other control on the main form (me.cID.SetFocus and then run the tasks normally to be run from the button. This way the button no longer has the focus and can be disabled/hidden etc
ASKER
Here's my solution: As I've said, the subform's form_Current() function calls a validation routine on the parent form. This routine, in turn, call a private sub: enableButtons(enable as boolean), to enable or disable various buttons on the parent from. If one of those very buttons caused the subform form_current() to fire, I get an error if enableButton(False) is called. So, simple solution:
private sub enableButtons(enable as boolean)
On Error Resume Next
me.thisButton.enabled = enable
me.thatButton.enabled = enable
:
:
exit sub
I'll split the point with dqmq and TOPIO since I'll use those ideas later and it's way too much work to do the "I've answered my own question" thing.
Thanks all
private sub enableButtons(enable as boolean)
On Error Resume Next
me.thisButton.enabled = enable
me.thatButton.enabled = enable
:
:
exit sub
I'll split the point with dqmq and TOPIO since I'll use those ideas later and it's way too much work to do the "I've answered my own question" thing.
Thanks all
This means then, if I read the code correctly, that the button will not be disabled like you wanted it to, you just igoner the error ?
https://www.experts-exchange.com/questions/21927195/Determine-what-control-has-focus.html