+ Reply to Thread
Results 1 to 7 of 7

Renaming Textbox Controls

  1. #1
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Angry Renaming Textbox Controls

    I am trying to sequentially rename the textboxes on my userform. Whatever I try I end up with errors. (Runtime error 382 'Could not set the name property. Can not set property at run time') I have tried adding the code to Userform_Initialize and everywhere else but with no success. Help would be appreciated. This is my code:
    Please Login or Register  to view this content.
    Last edited by BillWilts; 10-14-2010 at 08:04 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Renaming Textbox Controls

    The error means exactly what it says - you can't do that (why would you want to?)

    Note: when posting code on the forum, you must use code tags, please. I have added them for you here as it's your first post, but please use them in future.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Renaming Textbox Controls

    The reason behind the question is that I would like (as phase 2 of my current project) to build a multipage form with textboxes that can be added or deleted dynamically. Renaming the textboxes would allow me to simplify the process of populating the textboxes with data and writing the changes back to the spreadsheet. It's much easier to loop through a contiguous range!

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Renaming Textbox Controls

    If you add the textboxes dynamically, you can name them as you add them. I still can't see a reason for needing to change the names.

  5. #5
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Renaming Textbox Controls

    Quote Originally Posted by romperstomper View Post
    If you add the textboxes dynamically, you can name them as you add them. I still can't see a reason for needing to change the names.
    Thanks for pointing me in the right direction! I now have some code to create the boxes but am having a mental block regarding referencing them. Obviously they don't exist until the form is visible so 'Userform1.TextBox1.Value = ...' does not work. Can you give me some idea as to how they should be referenced?

    This is the code to create them.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Renaming Textbox Controls

    You can use:
    Please Login or Register  to view this content.
    in a loop. Typically though you would use a class to control the controls you add at runtime, depending on why you added them and what you are doing with them.

  7. #7
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Renaming Textbox Controls

    That works fine! Thanks for you help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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