Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Retrieve ActiveControl.Name from Subform Control

Posted on 2004-10-23
Medium Priority
Last Modified: 2012-08-14
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.


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.
Question by:Airgazm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Accepted Solution

Jokra_the_Barbarian earned 1000 total points
ID: 12391330
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

Set ctlCurrentControl = Me.ActiveControl

strControlName = ctlCurrentControl.Name
msgbox strControlName


Author Comment

ID: 12394923
ahh, I see how that works, thanks the focus worked.  

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question