Answers for "Clear al textboxes on a userform"

0

Clear al textboxes on a userform

Private Sub ClearFields_Click()

    Dim ctrl As Control      ' CREATE A CONTROL OBJECT.

    ' LOOP THROUGH EACH CONTROL, CHECK IF THE CONTROL IS A TEXTBOX.
    For Each ctrl In Me.Controls
        If TypeName(ctrl) = "TextBox" Then
            ctrl.Value = ""      CLEAR THE VALUE.
        End If
    Next ctrl
End Sub

' ASSIGN VALUES TO THE TEXTBOXES, WHEN FORM LOADS. (OPTIONAL)
Private Sub UserForm_Initialize()
    TextBox1.Value = "Arun"
    TextBox2.Value = "Computer"
    TextBox3.Value = "123456789"
End Sub
Posted by: Guest on August-07-2021

Browse Popular Code Answers by Language