I have a userform whose image is attached below.
What i need is when i press the submit button, it should promptv if there is any textbox left empty in the userform.
Here is my code:
Private Sub CommandButton1_Click()
Dim intTextBox As Integer
For intTextBox = 1 To 2
If Controls("TextBox" & intTextBox) = "" Then
MsgBox ("TextBox" & intTextBox & "blank. Please enter relevant data!")
Exit For
End If
Next intTextBox
End Sub
I am getting error at If Controls("TextBox" & intTextBox) = "" Then as could not find the specified object.
Kindly review and advise.
In order to find which
TextBox
is left empty, you need to loop through allControls
in your user_Form. Then, for eachControl
you need to check if it's typeTextBox
>> if it is, then check if it's empty.Code