Forum Discussion

cking1333's avatar
cking1333
Copper Contributor
Aug 01, 2024
Solved

Msgbox if all text boxes are blank

Good day,    Is there a way I can generate a msgbox when a specific button is clicked if all text boxes in a userform have been left blank? I know I can create code for each box individually but I'...
  • HansVogelaar's avatar
    Aug 01, 2024

    cking1333 

    For a command button named cmdCheck:

    Private Sub cmdCheck_Click()
        Dim ctl As Control
        Dim f As Boolean
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Then
                If ctl.Value <> "" Then
                    f = True
                    Exit For
                End If
            End If
        Next ctl
        If Not f Then
            MsgBox "All text boxes are empty!", vbInformation
        End If
    End Sub

Resources