Morning all,
I have some code which says
if a text box is empty show a msgbox asking user to input data into this textfield.
i then want only an O.K button to show on the msgbox but then no to continue with the sub.
If Me.txtLine2Rcon.Text = "" Then MsgBox("Please insert a running condition for Line 2 before you add it to the database", vbOKOnly)
Dim NewLongDesc As String
Dim RConv As String
Dim StkCodeV As String
RConv = Me.txtLine2Rcon.Text
NewLongDesc = Me.txtLongDesc.Text
StkCodeV = Me.txtStockCode.Text
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=10.10.0.25;Initial Catalog=RConditions;Persist Security Info=True;User ID=mbish;Password=mbish"
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO LN2(Stkcode, LongDesc,RCon) VALUES(@p1,@p2,@p3)"
cmd.Parameters.AddWithValue("@p1", StkCodeV)
cmd.Parameters.AddWithValue("@p2", NewLongDesc)
cmd.Parameters.AddWithValue("@p3", RConv)
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try
MsgBox("Record Added")
Me.line2add.Enabled = False
If Me.txtLine2Rcon.Text = "" Then Line2V = True
Me.line2add.BackColor = Color.Red
at the moment when there is no data in the txtbox you get the msgbox but then it runs theough all the code