• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Blank Textbox in Userform

Bomino

Member
Hello,
I have a UserForm with 10 Textboxes. When the user click the submit button and if there is any blank Textbox in the user form, I would like to have a warning message box to pop up. For example if Textbox1 is empty the message would be :
“Customer name was not entered ”
[ 'Customer name' being the label for Textbox1.]

Could anyone help me with a For...loop?
I hope my request make sense.
Thanks.
 
Hi ,

If you can upload your workbook , you will get code that works straightaway ; otherwise , you will get code which you will have to customize to suit your file.

Narayan
 
Hi ,

If you can upload your workbook , you will get code that works straightaway ; otherwise , you will get code which you will have to customize to suit your file.

Narayan

Narayan,
I will not be able to post my file for some reasons, but the attached file is just a generic file that I just created.
Thanks.
 

Attachments

  • Book1.xlsm
    15 KB · Views: 21
Add a label next to each text box
Hide it when the Form Initialises and display it if the Text box has no value

See attached

Select the userform and Press F5
 

Attachments

  • Book1.xlsm
    14.4 KB · Views: 30
I probably did not explain clearly my request. I would to have macro that will check for blank/empty textbox and then display a msgbox & exit.
I hope it make sense.
 
Narayan,
How would you amend the code if I just want txtb 2 to 5 to be checked for non Null String?
Code:
Private Sub CommandButton1_Click()
            Dim i As Integer
            For i = 1 To Me.Controls.Count
                With Me.Controls(i - 1)
                    If .Name Like "TextBox" & "*" Then
                        If .Value = vbNullString Then MsgBox .Name & " has not been entered !", vbExclamation
                    End If
                End With
            Next
End Sub

Thanks for your help.
 
Back
Top