Required Text Box


Posted by Michael on January 25, 2002 1:59 PM

How do I make a text box required so the user cannot exit the field without populating some data. Thank you



Posted by Damon Ostrander on January 25, 2002 2:35 PM

Hi Michael,

Just use the Textbox's Exit event:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Trim(TextBox1.Text) = "" Then
MsgBox "You must enter data"
Cancel = True
End If
End Sub

Obviously, this just makes sure the user enters something other than nothing or spaces. You could also use this opportunity to totally validate the data.

Damon