+ Reply to Thread
Results 1 to 4 of 4

Is it okay for two different userforms to have textboxes with the same name?

  1. #1
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Is it okay for two different userforms to have textboxes with the same name?

    Is it okay for two different userforms in the same workbook to have textboxes/comboboxes with the same name? e.g. txtName

    I have used the same textbox and combobox name for those boxes in different userforms without any issue. I just wanted to know if this might lead to some problem or issue in the future. Or, is it perfectly fine?

    Then, there is the question on command buttons. For example, if the two userforms have CLOSE command buttons, what do you do? Do you call both buttons "bttnClose" or call one "bttnUserform1Close" and the second "bttnUserForm2Close"?

    Would appreciate your advice as to what is the best way and any acceptable criteria for keeping textboxes/comboboxes with the same name.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Is it okay for two different userforms to have textboxes with the same name?

    The actual name of the text boxes is Userform1.txtName or Userform2.txtName, so the names are not actually the same. But, you might consider renaming the userforms to something more descriptive of their purpose.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Is it okay for two different userforms to have textboxes with the same name?

    Quote Originally Posted by protonLeah View Post
    The actual name of the text boxes is Userform1.txtName or Userform2.txtName, so the names are not actually the same. But, you might consider renaming the userforms to something more descriptive of their purpose.
    Really? Then this is awesome then as it will same a lot of time. Yes I agree userforms should be a bit distinct in terms of naming.

    You said the actual name is in the format nameofuserform.nameoftextbox, however when one clicks on a textbox and looks at the properties window at the very top, one only merely enters "txtComments", for example to create a textbox for comments. The "nameofuserform." part of the textbox name is not there visible in the Properties window next to where one writes the name for the textbox. Therefore are we saying the "nameofuserform." part of the textbox name is sort of "hidden" in the background?

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Is it okay for two different userforms to have textboxes with the same name?

    Yes, but it's not usually a good idea to refer to it directly like that

+ 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] userforms - populate multiple textboxes while typing in one
    By rodgersmg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2015, 06:12 AM
  2. All Textboxes in my userforms should be uppercase with a code
    By cemregunay in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-16-2015, 04:36 PM
  3. Replies: 0
    Last Post: 02-04-2015, 03:46 PM
  4. Linking TextBoxes to labels displayed on Excel/VBA userforms
    By pattersj in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-20-2014, 09:05 AM
  5. [SOLVED] Changing the state of Labels and textboxes in userforms
    By bfischer414 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2013, 09:53 AM
  6. Data validation on textboxes in userforms
    By nav505 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2013, 06:36 AM
  7. How share textboxes across userforms?
    By bdoodle in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-22-2011, 12:46 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