PDA

View Full Version : Problem with TxtBoxs and MsgBoxes



wildpianist
10-30-2007, 03:02 AM
Hello

I'm having another problem.

I've got a userform and what I want to do is when the value of the box equals nothing then a box to pop up saying "Please enter something!" or words to that effect.

However I can do



if txtBox1.Value="" then MsgBox "Please enter something"



then when I click OK for the box to disappear and not to log anything on my spreadsheet, I've tried Call UserForm_Initialize but it still comes up with the Thankyou box and thanking me for logging something (and logs something) albeit blank

Please help :help

I tried a Do Loop but ended up Looping "Please enter something" and then I had to Ctrl-Alt-Del excel

Hope this makes sense

Oh dear :(

Bob Phillips
10-30-2007, 03:17 AM
Hope this makes sense

No, it doesn't.

Are you saying that if nothing is entered, don't update the spreadsheet?

Are you saying that if nothing is entered, force them to enter something?

Are you saying that if you add a Do Loop around the entry, you can't escape it?

Confused? I am.

wildpianist
10-30-2007, 03:46 AM
Lol Silly me

Right....

If nothing is entered in txtBox1 through to TxtBox5 then do not update the spreadsheet and display message "Please enter something in ", txtBox

When OK is pressed then go back to the beginning (UserForm)

Then when something is entered in txtBox1, 2, 3, 4, 5, 6, 7 THEN update the spreadsheet.

Its basically to stop it updating useless stuff (blanks)

Thankyou for your help as always

Bob Phillips
10-30-2007, 04:53 AM
You don't want to create a loop, there is no way to correct it or exit.

Have an OK button and a Quit button. The OK button checkes the data and updates, the Quit button exits the form.

The OK button would then be


Private Sub cmdOK_Click()
Dim ans As Long
With Me
If TextBox1.Text = "" Or TextBox2.Text = "" Or _
TextBox3.Text = "" Or TextBox4.Text = "" Or _
TextBox5.Text = "" Then
MsgBox "Entry incomplete, vbok"
Else
Worksheets("Sheet1").Range("A1").Value = TextBox1.Text
Worksheets("Sheet1").Range("A2").Value = TextBox2.Text
Worksheets("Sheet1").Range("A3").Value = TextBox3.Text
Worksheets("Sheet1").Range("A4").Value = TextBox4.Text
Worksheets("Sheet1").Range("A5").Value = TextBox5.Text
End If
End With
End Sub