+ Reply to Thread
Results 1 to 12 of 12

Dynamically change TextBox name and label name on UserForm based on List value in sheet

  1. #1
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Dynamically change TextBox name and label name on UserForm based on List value in sheet

    Hi all,

    I hope you can help me.

    How can I dynamically change the Label name and the TextBox name on a UserForm based on a TRUE/FALSE criteria in a List?

    This is what I would like to do: If in my Admin sheet of my workbook, Name1 (column A) = TRUE (column B) then TextBox1 and Label1 in my UserForm2 dynamically change to 'Name1'

    thank you in advance!
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    You want to change the names of the controls dynamically at run time?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    When you launch the UserForm (UserForm_Initialize), it checks what the TextBox value should be. i am trying to create Admin settings/System Defaults

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    To dynamically rename controls on a form you would need to program to the VBE and I'm not sure that's possible at runtime.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    Actually I should clarify that, you could have something like this in the Initialize event,
    Please Login or Register  to view this content.
    but you wouldn't be able to refer to the textbox by it's 'new' name.

  6. #6
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    I am not too sure I understand.

    Will I be able to save the value that is entered in the dynamic textbox according to its name? I.e., if the textbox = textbox1, the data saves as textbox1.Value, when the textbox = WhatEver, it saves as WhatEver.Value

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    Actually, I had a mistake when testing - put the code in the wrong userform event.

    If you add this code to UserForm2 you'll get an error message.
    Please Login or Register  to view this content.
    Last edited by Norie; 01-20-2015 at 08:26 AM.

  8. #8
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    Hi Norie

    i am lost i do get an error.

    Do you have any suggestions perhaps?

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    I'm not really sure what you are trying to do.

    Why do you want/need to rename the controls?

    Couldn't you use their Tag property to store the username?

  10. #10
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    i have never attempted to do what i am trying.

    I have 10 possible field names, but at any given time, only 6 might be active on the UserForm (sort of like admin system configuration, where an administrator decides which fields are active).

    So, on the user form I would have 6 fields that need to dynamically change their names based on the admin settings.

    And, based on the textbox name, the databse will be updated with that data in the appropriate column. Does this makes sense?

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    Why not use a 2 column listbox dynamically populated with the appropriate fields?

    The first column would have the field name and the second column would be for the field value.

    The user could enter the field value for the selected field via a textbox.

  12. #12
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Dynamically change TextBox name and label name on UserForm based on List value in shee

    Intrigued...

    Could you share an example perhaps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Change the properties of a userforn textbox based on the backcolor of a label
    By chipnputt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2014, 10:47 PM
  2. [SOLVED] Change label caption's font color based on value in another textbox
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-19-2013, 01:59 PM
  3. Change Label Top on UserForm based on Count
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2012, 12:46 PM
  4. Userform Textbox and Label change from cell
    By Panic in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-20-2008, 08:36 PM
  5. Dynamically change list in a userform
    By Cumberland in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2007, 03:41 PM

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