I have an add button on my windows form that sometimes works and sometimes does not. Sometimes if I quickly double click it will add the new record, other times it just takes on normal click, still other times it will not insert the new reord at all. Does anyone knwo why this might be happening?
Here is my code:
Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
Dim strCommandText As String
Dim invnum As Integer
Dim intresult As Integer
invnum = txtinvnum.Text
If invnum > 20000 Then
strCommandText = "INSERT INTO InvoiceHistory (InvoiceDate,InvoiceNumber,LineSEQNo,CustomerNumber,ItemNumber,ProductLine,QuantityShipped,LastUnitPrice,DiscountP, PONumber) VALUES ("
strCommandText &= "'" & lbldatedisp.Text & "',"
strCommandText &= txtinvnum.Text & ","
strCommandText &= "'" & txtrefnum.Text & "',"
strCommandText &= "'" & lblcustdisp.Text & "',"
strCommandText &= "'" & cbotype.Items(cbotype.SelectedIndex) & "',"
strCommandText &= "'" & Mid$(cboprodln.Items(cboprodln.SelectedIndex), Len(cboprodln.Items(cboprodln.SelectedIndex)) - 3) & "',"
strCommandText &= "1," ' QuantityShipped
strCommandText &= txtdeduct.Text & ","
strCommandText &= "'0'," ' Discount
strCommandText &= "'" & txtrefnum.Text & "')"
Else
strCommandText = "INSERT INTO InvoiceHistory (InvoiceDate,InvoiceNumber,LineSEQNo,CustomerNumber,ItemNumber,ProductLine,QuantityShipped,LastUnitPrice,DiscountP, PONumber) VALUES ("
strCommandText &= "'" & lbltdatedisp.Text & "',"
strCommandText &= txtinvnum.Text & ","
strCommandText &= "'" & txtrefnum.Text & "',"
strCommandText &= "'" & lblcustdisp.Text & "',"
strCommandText &= "'" & cbotype.Items(cbotype.SelectedIndex) & "',"
strCommandText &= "'" & Mid$(cboprodln.Items(cboprodln.SelectedIndex), Len(cboprodln.Items(cboprodln.SelectedIndex)) - 3) & "',"
strCommandText &= "1," ' QuantityShipped
strCommandText &= txtdeduct.Text & ","
strCommandText &= "'0'," ' Discount
strCommandText &= "'" & txtrefnum.Text & "')"
End If
cmdaddinventory.CommandText = strCommandText
Try
OleDbConnection1.Open()
OleDbDataAdapter1.InsertCommand.CommandText = strCommandText
intresult = cmdaddinventory.ExecuteNonQuery
OleDbDataAdapter1.Update(DsInvoice1)
Catch Ex As OleDbException
System.Diagnostics.Debug.Write(Ex.Message)
End Try
OleDbConnection1.Close()
cmdfind_Click(sender, e)
End Sub
Here is my code:
Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
Dim strCommandText As String
Dim invnum As Integer
Dim intresult As Integer
invnum = txtinvnum.Text
If invnum > 20000 Then
strCommandText = "INSERT INTO InvoiceHistory (InvoiceDate,InvoiceNumber,LineSEQNo,CustomerNumber,ItemNumber,ProductLine,QuantityShipped,LastUnitPrice,DiscountP, PONumber) VALUES ("
strCommandText &= "'" & lbldatedisp.Text & "',"
strCommandText &= txtinvnum.Text & ","
strCommandText &= "'" & txtrefnum.Text & "',"
strCommandText &= "'" & lblcustdisp.Text & "',"
strCommandText &= "'" & cbotype.Items(cbotype.SelectedIndex) & "',"
strCommandText &= "'" & Mid$(cboprodln.Items(cboprodln.SelectedIndex), Len(cboprodln.Items(cboprodln.SelectedIndex)) - 3) & "',"
strCommandText &= "1," ' QuantityShipped
strCommandText &= txtdeduct.Text & ","
strCommandText &= "'0'," ' Discount
strCommandText &= "'" & txtrefnum.Text & "')"
Else
strCommandText = "INSERT INTO InvoiceHistory (InvoiceDate,InvoiceNumber,LineSEQNo,CustomerNumber,ItemNumber,ProductLine,QuantityShipped,LastUnitPrice,DiscountP, PONumber) VALUES ("
strCommandText &= "'" & lbltdatedisp.Text & "',"
strCommandText &= txtinvnum.Text & ","
strCommandText &= "'" & txtrefnum.Text & "',"
strCommandText &= "'" & lblcustdisp.Text & "',"
strCommandText &= "'" & cbotype.Items(cbotype.SelectedIndex) & "',"
strCommandText &= "'" & Mid$(cboprodln.Items(cboprodln.SelectedIndex), Len(cboprodln.Items(cboprodln.SelectedIndex)) - 3) & "',"
strCommandText &= "1," ' QuantityShipped
strCommandText &= txtdeduct.Text & ","
strCommandText &= "'0'," ' Discount
strCommandText &= "'" & txtrefnum.Text & "')"
End If
cmdaddinventory.CommandText = strCommandText
Try
OleDbConnection1.Open()
OleDbDataAdapter1.InsertCommand.CommandText = strCommandText
intresult = cmdaddinventory.ExecuteNonQuery
OleDbDataAdapter1.Update(DsInvoice1)
Catch Ex As OleDbException
System.Diagnostics.Debug.Write(Ex.Message)
End Try
OleDbConnection1.Close()
cmdfind_Click(sender, e)
End Sub