CodeItBetter Programming Another VB Programming Blog

How to clear all control’s values in a form

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'Controls - How to clear all control's values in a form
' Clear All Form Controls (using type of control)
On Error Resume Next
Dim ctl As Object
For Each ctl In Me.Controls
    If TypeOf Ctl Is CheckBox Then
        ctl.Value = False
    ElseIf TypeOf Ctl Is TextBox Then
        ctl.Text = ""
    ElseIf TypeOf Ctl Is Combobox Then
        ctl.Text = ""
        ctl.Clear
    End If
Next
 
' Clear All Form Controls (using name)
On Error Resume Next
Dim ctl As Object
For Each ctl In Me.Controls
    If Left(ctl.Name, 3) = "chk" Then
        ctl.Value = False
    ElseIf Left(ctl.Name, 3) = "txt" Then
        ctl.Text = ""
    ElseIf Left(ctl.Name, 3) = "cbo" Then
        ctl.Text = ""
        ctl.Clear
    End If
Next

Related posts:

  1. How to Clear all TextBoxes in a Form
  2. How to Clear all TextBoxes on the form
  3. How to clear the text in active control if the active form name is “frmCustomer”
  4. How to make a preferences Form
  5. How to clear the contents of all the items in an array of TextBox controls
  6. How to load the values of a recordset in a combo box
  7. How to select all text with Ctrl+A in all TextBoxes in a form
  8. How to count the number of textboxes in a form
  9. How to Enable/Disable all Controls in a frame
  10. How to reposition and resize all the controls on a form whenever the form is resized.

Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.