Scanning a barcode and triggering an event to search for UPC

instanceoftime

Board Regular
Joined
Mar 23, 2011
Messages
102
How can I trigger the change (If I use change event I will only get the first digit of the UPC) (UPC's are varying lengths)

The following code works (with a manual search button) and searches spreadsheet for the UPC# (hopefully helpful to others)

Code:
Private Sub txtbxUPCNumber_Change()
    
    Dim NotFound As Integer
    Dim arr As Variant
    Dim I As Long
    Dim str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As String
    




    NotFound = 0
    
    ActiveWorkbook.Sheets("Items").Activate
    
    Response = txtbxUPCNumber.Text


    ItemNumber = Response
    
    If Response <> False Then


        With ActiveSheet
            arr = .Range("A1:H" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        End With


        For I = 1 To UBound(arr)
            If arr(I, 7) = Response Then
                str1 = IIf(str1 = "", arr(I, 1), str1 & "|" & arr(I, 1))
                str2 = IIf(str2 = "", arr(I, 2), str2 & "|" & arr(I, 2))
                str3 = IIf(str3 = "", arr(I, 3), str3 & "|" & arr(I, 3))
                str4 = IIf(str4 = "", arr(I, 4), str4 & "|" & arr(I, 4))
                str5 = IIf(str5 = "", arr(I, 7), str5 & "|" & arr(I, 7))
                str6 = IIf(str6 = "", arr(I, 8), str6 & "|" & arr(I, 8))
            End If
        Next


        If str1 = "" Then
            AddUPC
            NotFound = 1
            
        Else
            Framed1.Visible = True
            lbxItemNumber.List = Split(str1, "|")
            lbxDescription.List = Split(str2, "|")
            lbxCost.List = Split(str3, "|")
            lbxDate.List = Split(str4, "|")
            lbxUPC.List = Split(str5, "|")
            lbxPrice.List = Split(str6, "|")
        End If


    End If
    
    
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,403
Messages
6,119,309
Members
448,886
Latest member
GBCTeacher

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top