Retrieve ActiveControl.Name from Subform Control

Hi, I'm trying to retrieve the ActiveControl.Name from a subform control, but I recieve the following error.

"The expression you entered requires the control to be in the active window."


form = billing
subform = line_items

My code was placed in the subform's "on current" property so I should get the control name everytime I click through the records in the subform.

Form_line_items(code)

Private Sub Form_Current()

Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name
msgbox strControlName

End Sub

I can't seem to figure out how to have this value returned.
Thanks for any help.
-Air
AirgazmAsked:
Who is Participating?
 
Jokra_the_BarbarianConnect With a Mentor Commented:
Try setting focus to a control before getting the active control. Also, use me.ActiveControl instead of Screen.ActiveControl.

Dim ctlCurrentControl As Control
Dim strControlName As String

Me.txt1.SetFocus
Set ctlCurrentControl = Me.ActiveControl

strControlName = ctlCurrentControl.Name
msgbox strControlName


0
 
AirgazmAuthor Commented:
ahh, I see how that works, thanks the focus worked.  
0
All Courses

From novice to tech pro — start learning today.