ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If then MsgBox (https://www.excelbanter.com/excel-programming/283708-if-then-msgbox.html)

Todd Huttenstine[_3_]

If then MsgBox
 
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



J.E. McGimpsey

If then MsgBox
 
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



In article ,
"Todd Huttenstine" wrote:

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



Todd Huttenstine[_3_]

If then MsgBox
 
Thanx, that worked.

Todd


"J.E. McGimpsey" wrote in message
...
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



In article ,
"Todd Huttenstine" wrote:

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






All times are GMT +1. The time now is 01:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com