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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I know what control has focus or pass the control reference?

Status
Not open for further replies.

aBill

MIS
Sep 24, 2002
26
US
Ok. Here is what I need to do. I have a block of code that is triggered by a Textbox control getting the focus. This code basically highlights the contents of the field so it can be overwritten by typing over the data.

I need to apply this code to all text boxes on the form. I do not want to paste the code into methods for each textbox control. I would rather have it in one method that is called from each textbox.

How can I do this? In my head, i think i would need to pass the reference to the control to the method and then use that to execute the code.

Any help would be appreaciated.

 
Turn the Code into a Public Function and then call it from the Got Focus Event of the Textbox

GotFocus =NameofCode()


"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 
Ok. I figured that much out, but thank you. How do I refer to the control in said code?

The control will be different each time the code is called, so i cannot hard-code the control name.

So I am back to this, how do i pass the refernce to the control or call the control by a generic name that will work in all code.
 
Hi!

You can get the control from the Screen object:

Dim cntl As Control

Set cntl = Screen.ActiveControl

now you can do what you need with the control.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Sweet. Thanks. That is what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top