Message Box if Text Box is Blank

  • Hi, I have created the following User Form


    I now would like to create a VBA code in such a way that if any of the Text Box is blank a message box would be displayed mentioning that the particular text box cannot be blank, and upon clicking the OK button in the message box it should again return to the same user form.


    For Eg. if all 3 text box are blank then message box should say "Please Enter Part Number, Particulars, Vendor Name"


    If 2 Text Box are Blank then it would mention the names of the blank text box, same way for one text box being blank.


    I would also like spaces to be counted as blank entry in the text box. Only spaces in between 2 words can be allowed in a text box, but that also in 2nd and 3rd text box and not the first one. (First Text Box no spaces are allowed)
    I have attached the userform for reference

  • Re: Message Box if Text Box is Blank


    Sir Works very well, but what I require as I had mentioned above is that I would also like spaces to be counted as blank entry in the text box. If there are spaces in 1st text box at start or in between then also it should give a message box.


    Only spaces in between 2 words can be allowed in a text box, but that also in 2nd and 3rd text box and not the first one. (First Text Box no spaces are allowed)


    Secondly all the blank entry should be mentioned in one message box only. In this case if all three text boxes are empty the message box pops up 3 times.
    What I mean to say that if all three text boxes are empty then message box should say "Please Enter Part Number, Particulars, Vendor Name", like what I have already posted above.


    Same way for 2 empty text, then only the name of 2 empty text box should appear and for 1 text empty text box one name should appear.

  • Re: Message Box if Text Box is Blank


    Sir there is still an error
    For Eg. If you enter only Particulars then instead of showing Enter Part Number and Vendor details it shows only Enter Vendor Details
    If you enter only Vendor details , no message box pops out for Part Number and Particulars
    If you enter Part Number and Vendor, no message pops out for Particulars
    If you ente spaces then also no message pops out, as required spaces not allowed for 1st text box. Spaces allowed only for 2nd and 3rd and that also between 2 words

  • Re: Message Box if Text Box is Blank


    Try this
    To A UserForm module

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!