How to clear all control’s values in a form
Posted on August 16, 2011
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 |