If then MsgBox

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

On Userform1, I have TextBox1. I am trying to acheive the following... If
when the user clicks CommandButton1 and Textbox1 equals "" or "Enter Stat
Name here", then I would like a message box to popup telling the user
"INVALID DATA". If when the user clicks CommandButton1 and Textbox1 does
not equal "" or "Enter Stat Name here", then I would like the code to
continue to the next part of the code which would be the message box saying
"Are you sure?" Right now I am getting errors in the first messagebox.

Below is what I have so far?

Private Sub CommandButton1_Click()
If TextBox1.Value = "" Or "Enter Stat Name here" Then
MsgBox("Invalid Data", vbOKOnly) = vbOKOnly
Else
End If
If MsgBox("Are you sure?", vbYesNo) = vbNo Then
Exit Sub
End If
End Sub

Thanx
Todd Huttenstine
 
One way:

Private Sub CommandButton1_Click()
With TextBox1
If .Value = "" Or .Value = "Enter Stat Name here"
MsgBox("Invalid Data", vbOKOnly)
Exit Sub
End If
End With
If MsgBox("Are you sure?", vbYesNo) = vbNo Then Exit Sub
'vbYes, so do something...
End Sub
 
Thanx, that worked.

Todd


J.E. McGimpsey said:
One way:

Private Sub CommandButton1_Click()
With TextBox1
If .Value = "" Or .Value = "Enter Stat Name here"
MsgBox("Invalid Data", vbOKOnly)
Exit Sub
End If
End With
If MsgBox("Are you sure?", vbYesNo) = vbNo Then Exit Sub
'vbYes, so do something...
End Sub
 
Back
Top