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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,647
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
 

ronnie76

Board Regular
Joined
Jul 26, 2007
Messages
101
Works perfect! Thanks a million.

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


Thanks again.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,282
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,683
Messages
5,637,787
Members
416,982
Latest member
lisam77

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
Top