Hello,
I have created a userform to scan a specific barcode and verify against list on another sheet. As of now, everything works perfectly, but I am having issues with the actual scanner. When I scan the barcode, only the last digit of the number is populated into the txt box. I would like the entire barcode number to be populated in my textbox, but I am unsure of where I am going wrong. Any help would be much appreciated.
I have created a userform to scan a specific barcode and verify against list on another sheet. As of now, everything works perfectly, but I am having issues with the actual scanner. When I scan the barcode, only the last digit of the number is populated into the txt box. I would like the entire barcode number to be populated in my textbox, but I am unsure of where I am going wrong. Any help would be much appreciated.
Code:
Private Declare Function sndPlaySound32 _
Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Private Sub ThisBID_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Dim BID As String
LastRow = Sheets("Stand Counts").Cells(Rows.Count, 1).End(xlUp).Row
BID = ThisBID
If LastBID = "" Then
LastBID = ThisBID
With Sheets("Stand Counts").Range("A1").Resize(LastRow, 1)
Set FoundBID = .Find(BID, LookIn:=xlValues)
If FoundBID Is Nothing Then
NotFoundError
Exit Sub
End If
With FoundBID
.Interior.Color = RGB(0, 255, 0)
End With
End With
Else
With Sheets("Stand Counts").Range("A1").Resize(LastRow, 1)
Set LastBIDRow = .Find(LastBID, LookIn:=xlValues)
Set FoundBID = .Find(BID, LookIn:=xlValues)
If FoundBID Is Nothing Then
NotFoundError
Exit Sub
End If
If LastBIDRow.Offset(1, 0) = FoundBID Then
With FoundBID
'.Select
.Interior.Color = RGB(0, 255, 0)
End With
Else
sndPlaySound32 scanSound, 0&
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Not In Order"
MsgBox "Order will be started from next Scan."
LastBID = ""
End If
End With
End If
ThisBID = vbNullString
cmd_Clear.SetFocus
ThisBID.SetFocus
ThisBID.SelStart = 0
End If
ThisBID.Text = ""
End Sub
Private Sub NotFoundError()
sndPlaySound32 scanSound, 0&
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Data not found." _
& vbCr & "Please check to make sure Plot Tag is correct."
MsgBox "Order will be started from next Scan"
LastBID = ""
ThisBID = vbNullString
cmd_Clear.SetFocus
ThisBID.SetFocus
ThisBID.SelStart = 0
End Sub
Private Sub cmd1_Click()
TxtNumber.Value = TxtNumber.Value & "1"
End Sub
Private Sub cmd2_Click()
ThisBID.Value = ThisBID.Value & "2"
End Sub
Private Sub cmd3_Click()
ThisBID.Value = ThisBID.Value & "3"
End Sub
Private Sub cmd4_Click()
ThisBID.Value = ThisBID.Value & "4"
End Sub
Private Sub cmd5_Click()
ThisBID.Value = ThisBID.Value & "5"
End Sub
Private Sub cmd6_Click()
ThisBID.Value = ThisBID.Value & "6"
End Sub
Private Sub cmd7_Click()
ThisBID.Value = ThisBID.Value & "7"
End Sub
Private Sub cmd8_Click()
ThisBID.Value = ThisBID.Value & "8"
End Sub
Private Sub cmd9_Click()
ThisBID.Value = ThisBID.Value & "9"
End Sub
Private Sub cmd0_Click()
ThisBID.Value = ThisBID.Value & "0"
End Sub
Private Sub cmd_Enter_Click()
Dim LastRow As Long
LastRow = Sheets("Stand Counts").Cells(Rows.Count, "G").End(xlUp).Row
Sheets("Stand Counts").Cells(LastRow + 1, "G").Value = ThisBID.Text
With Selection
.Interior.Color = RGB(99, 115, 115)
End With
Me.Hide
ThisBID.Text = ""
End Sub
Private Sub cmd_Clear_Click()
ThisBID.Text = ""
End Sub