Clear all Textboxes on a Form

Category:
Forms and Controls
Type:
Snippets
Difficulty:
Beginning
Author:
Chris Higgins

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
This is a simpler version of the subroutine at http://www.freevbcode.com/ShowCode.asp?ID=67. That version clears all edit controls on a form, including text boxes Rich Text controls, and custom controls that have a similar interface. This version has less code and works with text boxes only.

Simply place the code in a module then call the sub from within a cmdbutton click and pass in the current form. ex:

Private Sub cmdClear_Click()
ClearTextboxes frmMyForm
End Sub

This will clear all of the texboxes currently on the form.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: