Link to home
Start Free TrialLog in
Avatar of G Scott
G ScottFlag for United States of America

asked on

Determine which control has focus/active/clicked

I have a continuous form that has 48 text boxes (2 per hour) and a total of 4 rows. I want to know how to determine which of those boxes was clicked. When you click the box it opens up a popup form with a combo box. The value of the combo box is then passed back to the box that was clicked.

Maybe you need to look at it to see what is going on. It works if I program each and every textbox, but I am trying to 'automate' it a bit better.

Thanks for taking a look. MoldChanges.accdb

P.S. I have tried something like this on a few form events: Dirty, After_Update, Current. None of those worked.

Dim strActiveCtl As String

strActiveCtl = Screen.ActiveControl.Name

MsgBox strActiveCtl

And I may need to know how to do something like Forms!FormName! & Variable.  If that is possible.
Avatar of G Scott
G Scott
Flag of United States of America image

ASKER

P.S. I have tried something like this on a few form events: Dirty, After_Update, Current. None of those worked.

Dim strActiveCtl As String

strActiveCtl = Screen.ActiveControl.Name

MsgBox strActiveCtl
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America 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
SOLUTION
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 G Scott

ASKER

Thanks. You guys pointed me in the right direction. I used a bit of:

Public Function controlName(thecontrol As String)
Dim currentControl As String
Dim currentForm As String
currentControl = Screen.ActiveControl.Name
currentForm = Screen.ActiveControl.Parent.Name
DoCmd.OpenForm "Form1"
Forms!Form1!txtControlName = currentControl
Forms!Form1!txtCurrentForm = currentForm
Forms!Form1!txtRow = Forms!Form2(currentForm)!Row


Where I would call that fuction by, like you said pteranodon72, putting the control name on each and every call. Tedious, but it worked. Only to find out it really isn't a valid solution after all. Guess I need to really think it all the way through.

Thanks for the help. I learned something new. :)