Having a custom name in Textboxes, Listbox, ComboBox in VBA or VB.Net is a good strategy. So, it will be easy to debug the code or analyze the data.
If just relying on the default names is also good but it will get messy and it will be hard to control when there’s quite a few of textboxes, and list boxes. And the next person who will maintain the code will find it easier to debug or check the program when proper custom name is assigned to the controls. And that next person might be yourself. So, be gentle and be explicit in giving comments and assigning names to controls.
It doesn’t hurt to put a clear comment or an overview of what the piece of code does or what’s the input that the control is accepting. Because greediness breeds greediness, and it will bite back.
Anyway, to loop to all the custom or default names is quite easy.
Example, if there are 30 or more textboxes in a form. It can be done by a simple for loop like:
For x = 1 to 30
GetTboxvalue = Me.Controls(“Textbox” & …
If just relying on the default names is also good but it will get messy and it will be hard to control when there’s quite a few of textboxes, and list boxes. And the next person who will maintain the code will find it easier to debug or check the program when proper custom name is assigned to the controls. And that next person might be yourself. So, be gentle and be explicit in giving comments and assigning names to controls.
It doesn’t hurt to put a clear comment or an overview of what the piece of code does or what’s the input that the control is accepting. Because greediness breeds greediness, and it will bite back.
Anyway, to loop to all the custom or default names is quite easy.
Example, if there are 30 or more textboxes in a form. It can be done by a simple for loop like:
For x = 1 to 30
GetTboxvalue = Me.Controls(“Textbox” & …