PDA

View Full Version : Textbox help with msgbox



Killer Bud
05-14-2010, 11:32 AM
Ok, I think I am down to my last few problems.

Here is what I would like to do:


If Textbox5 has value then textbox 3 & textbox4 must be empty.
If not, then msgbox " Can only have a value in ....blah blah "

If textbox 3 & textbox 4 have value, then textbox 5 must be empty.
If not, then msgbox " Can only have a value in ....blah blah "


Any ideas??

mdmackillop
05-14-2010, 12:15 PM
Something like

Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox5) > 0 Then
If Len(TextBox3) + Len(TextBox4) > 0 Then MsgBox ("3 & 4 should be empty")
Else
If Len(TextBox3) = 0 Or Len(TextBox4) = 0 Then MsgBox ("3 & 4 should not be empty")
End If
End Sub

Killer Bud
05-14-2010, 01:04 PM
Thank you for the code. I am unable to get it to work though. I have posted the workbook as to get a better feeling of what I am trying to accomplish. As well, I have entered this code below to post a critical msgbox. It works well, but is there a way to have it only post the msgbox the one time unless another non-numeric value is put into the textbox? Right now it keeps popping up with the msg even when you hit delete.

Private Sub TextBox5_Change()
If Not IsNumeric(Me.TextBox5.Value) Then MsgBox "Enter a number only ", vbCritical, "Numbers Only"
With TextBox5
.SelStart = 100
.SelLength = Len(TextBox5)
End With
Range("a22") = TextBox5.Text
End Sub

mdmackillop
05-14-2010, 02:03 PM
I assumed you would complete the data entry in textbox number. Foolish of me I know. Try altering the code to suit the way you use it.

Killer Bud
05-14-2010, 02:37 PM
Forgive my ignorance, but can you please dumb it down a bit more for me.

"I assumed you would complete the data entry in textbox number"

.....what exactly am I supposed to do here....??

mdmackillop
05-14-2010, 03:18 PM
Looking at post 1, you say you have 3 boxes, 3, 4, 5. You wish to do something to compare the contents. You can only carry out the check after the third is completed. I assumed that was number 5.