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.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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!
 
Upvote 0
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!
 
Upvote 0
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.
 
Upvote 0
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!"
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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