Sorry about the last ones...And statements with IF's

Sorry about the last ones...And statements with IF's

Post by trickdo » Sat, 10 Jul 2004 06:52:25


I am trying to put a function into this user box so that if one of th
textboxes are empty, then nothing gets entered into the sheet. Ca
anyone help? I am stumped. I greatly appreciate it.

Private Sub OK_Click()

'This all happens when OK is clicked.

'if the first textbox is blank, then a message box pops up
'to tell you a value must be entered.

If TextBox1 = "" Then MsgBox "you must enter a name"
Range("a1") = TextBox1.Value


If TextBox2 = "" Then MsgBox "you must enter an age"
Range("a2") = TextBox2.Value


If TextBox3 = "" Then MsgBox "you must enter a gender"
Range("a3") = TextBox3.Value


'clears the text boxes for next use
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""

'sets the cursor in textbox1
TextBox1.SetFocus


'hides the userform when ok is clicked
Me.Hide

End Su
 
 
 

Sorry about the last ones...And statements with IF's

Post by Charle » Sat, 10 Jul 2004 07:23:01

trickdos,

The following is code that I came up with, but what you want is rreally
more than what you asked for. This will do as you asked.


Charles

Private Sub CommandButton1_Click()
With UserForm1
If .TextBox1.Value = "" Then
MsgBox " You must enter a name"
.TextBox1.SetFocus
Exit Sub
ElseIf .TextBox2.Value = "" Then
MsgBox " You must enter age"
.TextBox2.SetFocus
Exit Sub
ElseIf .TextBox3.Value = "" Then
MsgBox " You must enter gender"
.TextBox3.SetFocus
Exit Sub
End If
Range("A1").Value = .TextBox1.Text
Range("A2").Value = .TextBox2.Text
Range("A3").Value = .TextBox3.Text
.TextBox1 = ""
.TextBox2 = ""
.TextBox3 = ""
Unload UserForm1
End With
End Sub


---
Message posted from http://www.yqcomputer.com/