How to get the name of any text box clicked on

adamk

New member
Local time
Today, 03:02
Joined
Oct 24, 2012
Messages
5
Hello,

I have 480 textboxes in my form. What I am looking to do, is that any time any of thest textboxes are clicked (or double clicked) I want to then get the name of that textbox saved into a variable.

So I have created a public variable called tbName.

What I need is this:

- if the active control is a textbox then
- tbname = active control name.

It is important that I dont just take the active control name all the time as I want all controls other than textboxes to be igored. Secondly, under what event would I even put the code? Would it be the form Click event?

Appreciate any feedback.

Thanks
Adam
 
Try creating the function below in your forms module:

Code:
Function GetTextBoxName()
    tbName = Me.ActiveControl.Name
End Function

In the Property window in "On Got Focus" event of each textbox put the follow:
Code:
=GetTextBoxName()

This will assign the name of each text box to your variable.
 

Users who are viewing this thread

Back
Top Bottom