devxlogo

How to Reference a Control with a String Like a Name

How to Reference a Control with a String Like a Name

This is useful if you want to write a generic class to manage some common task with controls in your application. The variable uncontrol saves the name of the control you need to use. So, uncontrol = “the control’s name.”

Then, use the controls collection of a form in order to reference the control:

If TypeOf Me.Controls(uncontrol) Is TextBox Thendo somethingEnd If

devx-admin

Share the Post: