Home > Software engineering >  How can I get the name of the Textbox in which a function is being run in MS Access form?
How can I get the name of the Textbox in which a function is being run in MS Access form?

Time:10-31

I am trying to get create a function (or some expression) that can be run from any textbox on a Form, which will return the Name of the textbox as the Value of that textbox, i.e. each box will display it's name in the box itself.

I'm looking for something like Me.ActiveControl.Name, but that only returns the same value for each textbox. Is it possible to be self-referential like that? I haven't been able to find anything that does that.

CodePudding user response:

You can try rhis answer:

In a continuous form , all controlsthe 1 columnn havethe same name, it’s onecontrol used multiple times.

CodePudding user response:

Cell? self-referential?

The answer is Me.ActiveControl.Name which does return the name of the active control (textbox).

That name doesn't change from record to record. If you wish to identify individual records, use the ID of the record or the CurrentRecord property of the form.

You can make a control the ActiveControl of the form with:

Me!TheControlName.SetFocus

or:

Me.Controls("TheControlName").SetFocus

or loop the Controls collection of the form to list the textboxes:

Dim Control As Control

For Each Control in Me.Controls
    If Control.ControlType = acTextBox Then
        Debug.Print Control.Name
    End If
Next
  • Related