Reputation: 45
The code seems to be very good and nice organizing also the order follow is good, so where is the problem?
It never reaches to msgbox("2") ...
Public Function savefnn() As Boolean
If tco.Text = "" Then
MsgBox("Please Select Product")
tco.Focus()
ElseIf tco.Text = "Bags" Then
If tname.Text = "" Then
MsgBox("Please Enter Name")
tname.Focus()
ElseIf ttype.Text = "" Then
MsgBox("Please Choose Type")
ttype.Focus()
ElseIf Tcolor.Text = "" Then
MsgBox("Please Choose Color")
Tcolor.Focus()
End If
ElseIf tco.Text = "Balls" Then
If ttype.Text = "" Then
MsgBox("Please Choose Type")
ttype.Focus()
End If
ElseIf tco.Text = "Blades" Then
If tname.Text = "" Then
MsgBox("Please Enter Name")
tname.Focus()
ElseIf ttype.Text = "" Then
MsgBox("Please Choose Type")
ttype.Focus()
End If
ElseIf tco.Text = "Glues" Or tco.Text = "Cleaners" Then
If tname.Text = "" Then
MsgBox("Please Enter Name")
tname.Focus()
ElseIf tsize.Text = "" Then
MsgBox("Please Choose Size")
tsize.Focus()
End If
ElseIf tco.Text = "Rubbers" Then
If tname.Text = "" Then
MsgBox("Please Enter Name")
tname.Focus()
ElseIf Tcolor.Text = "" Then
MsgBox("Please Choose Color")
Tcolor.Focus()
End If
ElseIf tco.Text = "Shoes" Or tco.Text = "Socks" Then
If tname.Text = "" Then
MsgBox("Please Enter Name")
tname.Focus()
ElseIf tsize.Text = "" Then
MsgBox("Please Choose Size")
tsize.Focus()
ElseIf Tcolor.Text = "" Then
MsgBox("Please Choose Color")
Tcolor.Focus()
End If
ElseIf tco.Text = "Shorts" Or tco.Text = "TShirts" Or tco.Text = "Towels" Or tco.Text = "TrainigSuits" Then
If tname.Text = "" Then
MsgBox("Please Enter Name")
tname.Focus()
ElseIf tsize.Text = "" Then
MsgBox("Please Choose Size")
tsize.Focus()
ElseIf Tcolor.Text = "" Then
MsgBox("Please Choose Color")
Tcolor.Focus()
End If
ElseIf tco.Text = "Tables" Or tco.Text = "Nets" Then
If tname.Text = "" Then
MsgBox("Please Enter Name")
tname.Focus()
End If
Else
Return True
End If
End Function
Public Function isrecordvalid() As Boolean
If tco.Text = "Bags" Then
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [AllProducts] WHERE [ProductName] LIKE '%" & tname.Text & "%' And [Type] LIKE '%" & ttype.Text & "%' And [Color] LIKE '%" & Tcolor.Text & "%' ", cnxnString)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
MsgBox("Product Is Already Saved", vbCritical, "Error")
End If
ElseIf tco.Text = "Balls" Then
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [AllProducts] WHERE [Type] LIKE '%" & ttype.Text & "%' ", cnxnString)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
MsgBox("Product Is Already Saved", vbCritical, "Error")
End If
ElseIf tco.Text = "Blades" Then
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [AllProducts] WHERE [ProductName] LIKE '%" & tname.Text & "%' And [Type] LIKE '%" & ttype.Text & "%' ", cnxnString)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
MsgBox("Product Is Already Saved", vbCritical, "Error")
End If
ElseIf tco.Text = "Glues" Or tco.Text = "Cleaners" Then
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [AllProducts] WHERE [ProductName] LIKE '%" & tname.Text & "%' And [Size] LIKE '%" & tsize.Text & "%'", cnxnString)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
MsgBox("Product Is Already Saved", vbCritical, "Error")
End If
ElseIf tco.Text = "Shoes" Or tco.Text = "Socks" Or tco.Text = "Shorts" Or tco.Text = "TShirts" Or tco.Text = "Towels" Or tco.Text = "TrainingSuits" Then
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [AllProducts] WHERE [ProductName] LIKE '%" & tname.Text & "%' And [Size] LIKE '%" & tsize.Text & "%' And [Color] LIKE '%" & Tcolor.Text & "%'", cnxnString)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
MsgBox("Product Is Already Saved", vbCritical, "Error")
End If
ElseIf tco.Text = "Rubbers" Then
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [AllProducts] WHERE [ProductName] LIKE '%" & tname.Text & "%' And [Color] LIKE '%" & Tcolor.Text & "%'", cnxnString)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
MsgBox("Product Is Already Saved", vbCritical, "Error")
End If
ElseIf tco.Text = "Tables" Or tco.Text = "Nets" Then
Dim myadapter As New OleDbDataAdapter("SELECT * FROM [AllProducts] WHERE [ProductName] LIKE '%" & tname.Text & "%' ", cnxnString)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
MsgBox("Product Is Already Saved", vbCritical, "Error")
End If
Else
Return True
End If
End Function
Private Sub bs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs.Click
MsgBox("1")
If savefnn() = True Then
MsgBox("2")
If isrecordvalid() = True Then
MsgBox("3")
con.Open()
sql = "SELECT * FROM AllProducts"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AllProducts")
da = New OleDb.OleDbDataAdapter(sql, con)
con.Close()
start = System.DateTime.Now.ToString
Dim cb As New OleDb.OleDbCommandBuilder(da)
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("AllProducts").NewRow()
dsNewRow.Item("Product") = tco.Text
If tname.Enabled = True Then
dsNewRow.Item("ProductName") = tname.Text
Else
dsNewRow.Item("ProductName") = "None"
End If
If Button2.Enabled = True Then
dsNewRow.Item("Image") = Label40.Text
Else
dsNewRow.Item("Image") = "None"
End If
If tch.Enabled = True Then
dsNewRow.Item("Charac") = tch.Text
Else
dsNewRow.Item("Charac") = "None"
End If
If ttype.Enabled = True Then
dsNewRow.Item("Type") = ttype.Text
Else
dsNewRow.Item("Type") = "None"
End If
If tsize.Enabled = True Then
dsNewRow.Item("Size") = tsize.Text
Else
dsNewRow.Item("Size") = "None"
End If
If Tcolor.Enabled = True Then
dsNewRow.Item("color") = Tcolor.Text
Else
dsNewRow.Item("Color") = "None"
End If
dsNewRow.Item("Date") = start
ds.Tables("AllProducts").Rows.Add(dsNewRow)
da.Update(ds, "AllProducts")
s = 1
MsgBox("New Product Saved")
store = tname.Text
store1 = start
bus.Enabled = True
clear1()
MsgBox("4")
End If
End If
End Sub
Upvotes: 0
Views: 77
Reputation: 147
You are not reaching MsgBox("2") because your function savefnn() is not returning true. In scenarios where you are not getting the expected results you can use breakpoints in your code to debug it. You can also apply watch to find the current values.
And its better to use Select Case for the kind of nesting you are using.
Upvotes: 2
Reputation: 26
I would like to suggest you to use 'SWITCH CASE' instead of nested 'IF'.
Performance of program would be improved and you could have better clearance on logic as well.
Upvotes: 1