Emptying textboxes in a VBA form using a for next loop

Can I clear multiple textboxes in a loop please. I have tried the code below but it has the following error. "Method or data member not found (Error 461)"
Dim a
  For a = 1 To 5                                    
       If UserForm1.Textbox(a).Text = "DATE" _
       Then UserForm1.Textbox(a).Text = vbNullString
    Next
UserForm1.PrintForm                                                 ' Print form
------------------------------------------------------------------------------------------------ Thanks John
Vishesh's picture

Try this then... Dim

Try this then...
    Dim objText     As Control
    Dim intCount    As Integer
 
    intCount = 0
 
    For Each objText In UserForm1.Controls
        If UCase(TypeName(objText)) = "TEXTBOX" Then
            If objText.Text = "DATE" Then
                intCount = intCount + 1
                objText.Object.Text = ""
                If intCount = 5 Then Exit For
            End If
        End If
    Next objText
    Set objText = Nothing
    UserForm1.PrintForm

Try this then

Vishesh,

This works great, thanks very much for your help and such a quick responce. Have a good night.

Kind regards
John

Vishesh's picture

Emptying Textboxes

Try this code...
    Dim objText As Control
 
    For Each objText In UserForm1.Controls
        If UCase(TypeName(objText)) = "TEXTBOX" Then
            If objText.Text = "DATE" Then
                objText.Object.Text = ""
            End If
        End If
    Next objText
 
    UserForm1.PrintForm
 
    Set objText = Nothing

Emptying textboxes

Vishesh,
Thanks for such a quick reply unfortunately it empty’s all of the textboxes and not just the first five. Any other ideas?

Regards
John