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'm thinking there must be a way to combine everything together and generate the msgbox.
Thanks in advance for any assistance!!!
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
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
- cking1333Copper ContributorWonderful....thanks for a quick reply with code that works perfect!!!!!