+ Reply to Thread
Results 1 to 8 of 8

Index number for controls (eg Textbox) in userform

  1. #1
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Index number for controls (eg Textbox) in userform

    Greetings,

    Do userform controls have an index number that can be referred to in any code such that renaming the control will not impact the code?

    Many thanks
    Asha
    Last edited by asha3010; 07-07-2010 at 09:56 AM.

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Index number for controls (eg Textbox) in userform

    They're 'indexed' in count form as they're added, but these aren't static, it you delete control 3 control 4 becomes control 3...

    i.e. no, just get the names right
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Index number for controls (eg Textbox) in userform

    the userform has a Controls collection that may be of use.

    what exactly are you trying to do or avoid?
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Index number for controls (eg Textbox) in userform

    If you rename the Control, you will have to change the control name in the code.

  5. #5
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Index number for controls (eg Textbox) in userform

    Sorry asha, not exactly what you were looking for - but at least I'm not the only one not helping much! (with utmost respect)

    They do have a 'tag' which can be used by (lazy) programmers to pass arguments between subs. (I do this, although I'm trying to shake the habit!).

    So you could write code like:
    Please Login or Register  to view this content.
    I am, I'm afraid, not being entirely serious with this suggestion, but it fits...

  6. #6
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Index number for controls (eg Textbox) in userform

    Thanks to all for your response.

    Andy,

    I am writing a code for updating a worksheet with the data in the userform. As an eg

    Please Login or Register  to view this content.
    So, if I change the name of any of the above controls, I will have to update the code. Am trying to minimise code maintenance, hence the question.

    Let me know if I am not clear.

    Thanks a lot
    Asha

  7. #7
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Index number for controls (eg Textbox) in userform

    @ Cheeky Charlie,

    I have already tagged some of the controls for another purpose (formatting the display)!

    Even if I remove the existing tags, I am not sure how to use your code for the purpose of updating a worksheet.....

    Thanks a lot
    Asha

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Index number for controls (eg Textbox) in userform

    technically then you could do this

    Please Login or Register  to view this content.
    But I wouldn't.

    I'm not sure how this fits into maintanence. If you are worried about the relevance of names for the controls do the design/thinking before rather than after.
    Another impact of changing names afterwards is any event code will still require sorting out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1