A simple Clear All Controls on Form -- Just 4 Lines!

Submitted on: 2/1/2015 8:58:00 AM
By: Cor! (from psc cd)  
Level: Beginner
User Rating: By 31 Users
Compatibility: VB 6.0
Views: 2903
     Need to perform the same action on multiple controls in your form? Then this simple code might just be for you.. This particular example will show you the most efficient way to clear every text box on a form. This method can be especially useful if you're adding and removing controls during the development of a project.


I guessed there must be a better way than hard-coding each control name, but I searched PSC and couldn't find anything to do the job. So after I worked it out I felt this simple method should be added to PSC so those who don't already know how to do it can benefit too.

Dim Control As Control
For Each Control In Me
If TypeOf Control Is TextBox Then Control.Text = ""
Next Control

Please vote if you learnt something useful.


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.