0

i dont know where is the problem :( Sorryy

Private Sub Tmbl_Del_Click()
    Dim sampah As TextBox
    Dim sampah2 As ComboBox
    
    For Each sampah In Jurnal
    If IsEmpty(sampah) Then
        If sampah.Name <> TxtTanggal Then
            sampah.Value = ""
        End If
    End If
    Next
    For Each sampah2 In Jurnal
            
            sampah2.Value = ""
    Next
End Sub

i tried to clear all the content in TextBox and ComboBox in my VBA Form except the TextBox named 'TxtTanggal'

Ike
  • 9,580
  • 4
  • 13
  • 29

1 Answers1

0

Try adopting the following code, which loops through each control, and checks whether the control is either a TextBox or ComboBox. If so, it clears the content, unless the control is named "TextBox1".

Dim ctrl As Control

For Each ctrl In Me.Controls
    Select Case TypeName(ctrl)
        Case "TextBox", "ComboBox"
            If ctrl.Name <> "TextBox1" Then
                ctrl.Value = ""
            End If
    End Select
Next ctrl
Domenic
  • 7,844
  • 2
  • 9
  • 17