Operating on multiple controls in a form
By: Lorenzo Dalla Vecchia Date: 13/10/1998

Sometimes you will probably need to work on many controls of a form. The following code shows you how to set the Visible property of all controls of a form to False. You may use it to set other properties as well.

Dim ctl As Contr      'Store current control
For Each ctl in formname.Controls
   ctl.Visible = False 
'Set property
Next ctl

formname is the name of the form.

You may also work with only a type of controls. The following code clears all textboxes on a form.

Dim ctl As Control          'Store current control
For Each ctl in formname.Controls
   If TypeOf ctl Is TextBox Then
      ctl.Text = ""        'Set property
   End If
Next ctl

And you can replace TextBox with the type of control you are working on (i.e. Label, Picture, CommandButton, etc.).

Click Here!


Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
Webmaster's e-mail: webmaster@vbprogzone.cjb.net
Hosted by InWind: www.inwind.it