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
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.
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.
the userform has a Controls collection that may be of use.
what exactly are you trying to do or avoid?
If you rename the Control, you will have to change the control name in the code.
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:
I am, I'm afraid, not being entirely serious with this suggestion, but it fits...for each control in userform.controls if control.tag = "name" then set mycontrol = control exit for end if next control 'do something with mycontrol
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
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.'Copy the data to the database wDest.Cells(iRow, 1).Value = Me.ComboBox_Co.Value wDest.Cells(iRow, 3).Value = Me.TextBox_Date.Value
Let me know if I am not clear.
Thanks a lot
Asha
technically then you could do this
But I wouldn't.Const MY_TEXTBOX = "Textbox_Date" const MY_COMBOBOX = "ComboBox_Co" Sub x() 'Copy the data to the database wDest.Cells(iRow, 1).Value = Me.controls(MY_COMBOBOX).Value wDest.Cells(iRow, 3).Value = Me.controls(MY_TEXTBOX).Value End Sub
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.
@ 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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks