For more ideas from the rest of the team you could check
http://www.experts-exchang
Main Topics
Browse All TopicsHow can I determine which control currently has focus on a form?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
For more ideas from the rest of the team you could check
http://www.experts-exchang
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?
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
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
Business Accounts
Answer for Membership
by: TOPIOPosted on 2007-06-13 at 09:28:52ID: 19275869
Me.ActiveControl will return what you're looking for, but I don't know of any single Form-level event you could put code in that would fire each time the user moves between controls. Typically, you'd add a single function that would handle this, then call that function from each control's GotFocus event (as you are apparently doing now) ... so something liket his:
idth
Function SetWidth(ControlName as STring)
Select Case ControlName
Case "cboSomeCombo"
Me.Controls(ControlName).W
Case Else
'/<no code here>
End Select
End Function
Then in the GotFocus event of your controls, 1 single line:
Sub YourControl_gotFocus()
SetWidth Me.Name
End Sub
At least with this you can copy/paste that one line into each controls GotFocus handler ...