Validating that a UserForm TextBox is not left empty

ronnie76

Board Regular
Joined
Jul 26, 2007
Messages
101
I have a user form in which 4 of the 12 Text boxes need to filled in.
Is there a way without using command button to validate that those text boxes have information in them?

Thanks for the help
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
maybe this can give you an idea

Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value = "" Then
    MsgBox "you left it empty"
End If
End Sub

when the user enters the textbox and leaves the textbox without entering any data a msg will popup...

if you dont want the user to be able to move on you have to do some type of error checking at the button click event
 
Upvote 0
Works perfect! Thanks a million.

One other question though how does the (ByVal Cancel As MSForms.ReturnBoolean) make the code work?


Thanks again.
 
Upvote 0
Actually the Cancel isn't being used in the posted code.

To use it add this.
Code:
Cancel = True
What this does is 'cancel' the exit from the control.
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top