Forum Discussion
cking1333
Aug 01, 2024Copper Contributor
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'...
- Aug 01, 2024
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
HansVogelaar
Aug 01, 2024MVP
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 Subcking1333
Aug 01, 2024Copper Contributor
Wonderful....thanks for a quick reply with code that works perfect!!!!!