+ Reply to Thread
Results 1 to 6 of 6

Do userform controls have an index number

  1. #1
    Forum Contributor
    Join Date
    03-13-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    136

    Do userform controls have an index number

    The form that I have created has a number of controls that are created at runtime. If a user triggers the event that originally created the controls, I want to be able to delete all of the controls before recreating them. Is there a loop that can delete all of the newly created controls? I have 9 controls on the form that need to stay put but everything after those 9 controls I want to delete. Is there something like:

    Please Login or Register  to view this content.
    ??
    Last edited by jerseyguy1996; 12-18-2009 at 04:37 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,202

    Re: Do userform controls have an index number

    There is no Index number, can you explain more fully what you are doing. A sample workbook might help
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Do userform controls have an index number

    Hello jerseyguy1996,

    Each control is part of the UserForm's Control collection. Each object in a collection can be referenced either by it key value, a string that holds the objects name, or an index value that points to position within the collection.

    If you loop through the collection by index value, you will still need to check the control's name against a list. The easiest way to do this is with a Select Case statement that contains the names of the controls you don't want to delete. Add the names to the macro you want to keep.
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-13-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Do userform controls have an index number

    Quote Originally Posted by Leith Ross View Post
    Hello jerseyguy1996,

    Each control is part of the UserForm's Control collection. Each object in a collection can be referenced either by it key value, a string that holds the objects name, or an index value that points to position within the collection.

    If you loop through the collection by index value, you will still need to check the control's name against a list. The easiest way to do this is with a Select Case statement that contains the names of the controls you don't want to delete. Add the names to the macro you want to keep.
    That's perfect. I actually got away with a slight variation of that. I know that the controls that I want to keep are indexed 0 - 8 so my code is:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-13-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Do userform controls have an index number

    Its kind of interesting to me that the index number goes after "Remove" rather than after "Controls". Why is this? It seems that with all of the other collections that I have worked with, the index number goes after the collection name as in:

    Please Login or Register  to view this content.
    rather than

    Please Login or Register  to view this content.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Do userform controls have an index number

    Hello jerseyguy1996,

    I have often wondered the same thing.

+ 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