Home > How-To Library > Controls

How to clear all control's values in a form

**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * ****************************************************************
' 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

If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.