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?
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?