Require input in controls text box

jo.g

New Member
Joined
Dec 5, 2005
Messages
22
Hello, new to the board. I'm using a control text box on a template, I named the box Originator. I want to require the user to fill in their name - can someone help me please! Something short and sweet.
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

jo.g

New Member
Joined
Dec 5, 2005
Messages
22
I haven't received any feedback, but I added this code:

Private Sub Originator_Change()
If Originator.Text = "" Then
MsgBox "You Must Enter Your Last Name First Name"
End If
End Sub

But it only works if I add some text into the box and then backspace and delete everything. I need something that will check to see if the text box is empty after the user clicks out of the box. Also, add a check if the user tries to save the file without filling in the text box. Please help!
 

jo.g

New Member
Joined
Dec 5, 2005
Messages
22
It's funny, I'm replying to my own post, it's like I'm talking to myself. I found this, but haven't tried it out yet:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If Len(TextBox1) = 0 Then
MsgBox "You have to insert value in TextBox1"
Cancel = True
End If

End Sub

Any comments? Hello... hello... hello, is there anybody out there!
 

jo.g

New Member
Joined
Dec 5, 2005
Messages
22
So far I've tried the following that I have found on different boards and placed the code in my Sheet1 code window. I'm obviously hacking since I've never done this before...

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Len(TextBox1.Text) = 0 Then
MsgBox "Required field."
TextBox1.Text = Left(TextBox1.Text, 5)
End If
End Sub
-------------------------
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value = "" Then
MsgBox "Required Field."
SendKeys "+{TAB}"
End If
End Sub
------------------------

I'm trying to make the user put something in the empty field when they try to tab over or access the next field. Or it would be great if I could do a check for all required fields when the form is completed.
 

jo.g

New Member
Joined
Dec 5, 2005
Messages
22
just wanted to share what i ended up doing... i created a command button and named it "submit form", then I called a module to verify all the required textboxes:

Private Sub CommandButton1_Click()
If Originator = "" Then
MsgBox "You must enter Last Name First Name in the Originator field"
End If

If Platform = "Select Platform" Then
MsgBox "You must select a valid Platform from the dropdown list."
End If
....

there is probably an easier way, but i had to get going on this... "thanks for all your help jo" - "Oh, you're welcome!"
 

Watch MrExcel Video

Forum statistics

Threads
1,118,535
Messages
5,572,759
Members
412,482
Latest member
arooshrana2
Top