none
Get the Index number of a textbox RRS feed

  • Question

  • Thanks for taking the time to read my question.

    How do I return the index number of a textbox on a form?

    me.Controls(txtInput)

    Items(Index) as object

    Controls() needs a number not a name. How do I find out what number txtInput is?

    Thanks,
    Brad

    Friday, March 11, 2016 11:01 PM

Answers

  • You can use

    Me.txtInput

    or

    Me.Controls("txtInput")


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by mbrad Monday, March 14, 2016 12:56 PM
    Friday, March 11, 2016 11:04 PM

All replies

  • You can use

    Me.txtInput

    or

    Me.Controls("txtInput")


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by mbrad Monday, March 14, 2016 12:56 PM
    Friday, March 11, 2016 11:04 PM
  • Controls() needs a number not a name.

    Hi Brad. As Hans said, Controls() can take a name. Just make sure you enclose the name in quotes.
    Saturday, March 12, 2016 1:42 PM
  • Controls() needs a number not a name.

    Hi Brad. As Hans said, Controls() can take a name. Just make sure you enclose the name in quotes.

    Hi,

    In addition to Hans there are some more syntaxes:  Me!txtInput  or Me("txtInput").

    But instead of the literal value of the control name, you can also use a variable containing the literal value. In the case you must use the Me(var1) or Me.Controls(var1) syntax, but now without quotes.

    Imb.

    Saturday, March 12, 2016 5:48 PM
  • In addition to Hans there are some more syntaxes:  Me!txtInput  or Me("txtInput").

    Just so the OP is fully in the picture (or possibly just more confused!), the reason that the above works is because the Controls collection is the default property of the Form class.  As a default property can be omitted, Me("txtInput") is consequently just a shorthand for Me.Controls("txtInput").  In fact it's even more of a shorthand than that as the default property of the Controls class is the Item property, so it's really a shorthand for Me.Controls.Item("txtInput").

    To put a few more cats among the pigeons, the Me keyword returns a reference to the instance of the class in which the code is running, so if two or more instances of the form were open, Me.Controls.Item("txtInput"), or any of its abbreviated syntaxes, would return a different value in the module of whichever instance of the form it is called.


    Ken Sheridan, Stafford, England



    • Edited by Ken Sheridan Saturday, March 12, 2016 6:50 PM Typo corrected.
    Saturday, March 12, 2016 6:46 PM
  • Hi, mbrad

    The form’s controls collection, in common with all other collection objects, does not have a method which returns the index for a given object. In part this is because the position of an item within a collection may vary over time, depending on whether or not new objects are added to the collection or deleted from it.

    So you can use

    Me("NewData")

    Me.Controls("NewData")

    The following link may help you to get more information.

    control object Access

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, March 14, 2016 3:14 AM
    Moderator
  • Hi Hans,

    Thank you so very much for your quick reply.

    I knew that.... Friday was a long day :-). I appreciate your help.

    Brad

    Monday, March 14, 2016 12:56 PM