VBA user form and barcode scannig problem

dan5003

New Member
Joined
Mar 15, 2024
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
Hello guys,

I'm having some issues with a vba form that i created. I'll post he vba code, but before that i will try to explain the function.
There is excel file that i'm going to use a inventory management system. i created this form where i have to scan a barcode in order to put the product in the "warehouse" and when necessary to take it out of there.
the problem is that when i scan with the barcode in a random field in excel i see the barcode, when i open the form and try to scan it it doesn't work. (the interesting part is that when i copy and then paste the same barcode in the field it is working)

This is the code for the barcode box:
(it also disply me a picture and name of the product based on the barcode)

Private Sub txtBarcode_Change()
Dim barcode As String
Dim productName As String
Dim lookupSheet As Worksheet
Dim lookupRange As Range
Dim lookupCell As Range

' Get the entered barcode
barcode = Me.txtBarcode.Text

' Check if the barcode is not empty
If Len(barcode) > 0 Then
' Load and display the image
imgProduct.Picture = LoadPicture("C:\Users\DAN\Desktop\vending machine\pics\" & barcode & ".jpg")
imgProduct.Visible = True
imgProduct.Width = 300
imgProduct.Height = 260

' Find the barcode in the lookup table
Set lookupSheet = ThisWorkbook.Sheets("Database") ' Change "Database" to the actual name of your lookup sheet
Set lookupRange = lookupSheet.Columns("C") ' Assuming barcodes are in column C and product names are in column B

Set lookupCell = lookupRange.Find(What:=barcode, LookIn:=xlValues, LookAt:=xlWhole)

' If barcode is found, retrieve the corresponding product name
If Not lookupCell Is Nothing Then
productName = lookupCell.Offset(0, -2).Value ' Offset by 2 columns to get the product name in column A

' Display the product name
Me.lblProductName.Caption = productName
Me.lblProductName.Visible = True
Else
' Barcode not found in lookup table
Me.lblProductName.Caption = "Product not found"
Me.lblProductName.Visible = True
End If
Else
' Barcode is empty, hide the image and product name
imgProduct.Picture = LoadPicture("") ' Clear the picture
imgProduct.Visible = False
Me.lblProductName.Caption = "" ' Clear the product name
Me.lblProductName.Visible = False
End If
End Sub


and this is the userform:

Any ideas, where it might be the problem?
 

Attachments

  • in.jpg
    in.jpg
    29.2 KB · Views: 25

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
The Scanned Barcode textbox on the form must have the focus while you're scanning. Best if the form is modal.

Maybe not relevant for you since the scanned code appears on sheet, but still - check, if such settings are available with the scanner software, how the scanner is passing the code to the receiving app - simulating keystrokes, clipboard or some other method. Try to change it until it works for you. Normally keystrokes simulation works best.
 
Upvote 0

Forum statistics

Threads
1,223,939
Messages
6,175,533
Members
452,652
Latest member
eduedu

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