Hey guys,
I am having trouble with keypress event for a button that I have.
This button is programmed to run a function to add data to the database when the button is pressed.
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
funcAdd()
End Sub
Private Sub btnAdd_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles btnAdd.KeyPress
funcAdd()
End Sub
Public Function funcAdd()
If txtModel.Text = Nothing Or txtSerial.Text = Nothing Or txtControlID.Text = Nothing Then
MessageBox.Show("Please complete required fields", "Incomplete Fields", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return Nothing
Exit Function
ElseIf txtControlID.TextLength <> 10 Then
MessageBox.Show("Invalid Control ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
Exit Function
End If
'Creates and instance where the function funcAddItem is called.
'Values that are entered into the database is passed onto the function as parameter
Try
shipCls.funcAddItem(txtOutID.Text, txtModel.Text, txtSerial.Text, txtControlID.Text)
Me.SelectViewByItemTableAdapter.FillBy(Me.GCR_ICDataSet.SelectViewByItem, txtOutID.Text)
Me.SelectViewByModelTableAdapter.Fill(Me.GCR_ICDataSet.SelectViewByModel, txtOutID.Text)
Catch ex As Exception
MsgBox("A problem was detected while adding data" & vbCrLf & _
"Please contact system administrator for further assistance", MsgBoxStyle.OkOnly, "System Error")
End Try
DataGridView_ByItem.Refresh()
txtModel.Text = Nothing
txtSerial.Text = Nothing
txtControlID.Text = Nothing
txtModel.Focus()
Return Nothing
End Function
Currently all of the data that are entered is done by using a barcode scanner, and when the user need to press button to execute function, the user need to come to the computer after each item is scanned to press or click btnAdd.
But I want the user to be able to scan an extra barcode which will then register as keypress event and activate the button.
The problem is our scanner guns are programmed to tab over to next index after each scan so when I scan an extra barcode, the program will activate the button but also same time print rest of the scanned characters in the next index tab with is a textbox.
I was wondering if there is a way for the event to excute only when tab is pressed.