Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting object with focus. 1

Status
Not open for further replies.

SmokingCrater

Programmer
Jun 29, 2001
47
0
0
US
I don't think this hard but I can't remember an easy way to do it and the search isn't working for me. How can you obtain which object has the focus on a form? When i do a requery (refresh) of the screen I want the cursor to return to where it was before the refresh. I want to set Object o = the control that has the focus so after the refresh, the object can be returned the focus.

Thanks.
 
Try:

Me.Combo71.SetFocus

Combo71 is the name of my control. Me refers to the current form. Let me know if this helps.
 
gcole, that helps to set the focus. I'm looking to determine what the "combo71" portion is. I'm looking for a quick easy (and dynamic) way to determine what the control is that the focus must get set to.
 
You can use the ActiveControl property to get this data. Try this code:

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

That was taken right out of help from Access and will set strControlName equal the the control that currently has focus.



Joe Miller
joe.miller@flotech.net
 
Thanks Joe. I knew I had read it somewhere but couldn't remember where. Thanks again.
 
What if you run into a situation where you want to specify the "setfocus", but all you get is "value" as your only option in the list box. What then?
 
This works unless the control is in a frame - ActiveControl will return the name of the frame, but not the control in the frame. How can I return the name of the control in that case?
Cheers,
Robyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top