Tag Archives: Clear Text

Clear all Textboxes on Form in VB 6.0

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
 

This code will clear all textbox controls on the form. The second code near the bottom of the post will clear all control but bypassing certain ones.

'Visual Basic 6.0

Public Sub ClearAllText(ByVal frm As Form, ByVal ctl As Control)

  For Each ctl In frm

    If TypeOf ctl Is TextBox Then

      ctl.Text = ""

    End If

  Next

End Sub

Updated! 02/07/2008: A request was made on how to clear or manipulate all controls on a form but to bypass/skip/passby certain controls named a certain name.

Clear All Textbox Controls except those with Specific Names

'

'Setup a Control object.

Dim ctl As Control

'

'Go through each control the form has.

For Each ctl In Me.Controls

'

'If the control type if a Textbox control, then…

  If TypeOf ctl Is TextBox And Not ctl.Name = "txt2" Then

    '

    'Change the text of the controls to "" (Nothing, Blank)

    ctl.Text = “”

  EndIf

Next

Revisited: 2015