new TextBox doesn’t work properly when I scan barcodes

I’m working on this store checkout system where I can scan barcodes into TextBoxes on a UserForm. Next to each TextBox, there’s supposed to be a Label showing the product name and price. I’ve got it set up so I can keep adding more TextBoxes as I scan more barcodes. But here’s the problem: the order the barcodes show up in the TextBoxes is all over the place. The sequence on which TextBox the new barcode will appear is 1st, 2nd, 1st, 2nd, 3rd, 1st, 2nd, 3rd, 4th, 1st… and so on.

Regarding the labels, they’re only showing info from the first TextBox. I want it so that when I scan a new barcode, a new TextBox pops up automatically, and the new barcode shows up there.

Below is the code I’m currently using:

Private count As Integer

Private Sub BarcodeTextBox_Change()
    Dim scannedCode As String
    Dim foundProduct As Range
    
    ' Get the scanned barcode from the TextBox
    scannedCode = BarcodeTextBox.Value
    
    ' Search for the scanned product code in the "Products" worksheet
    Set foundProduct = Worksheets("Products").Columns(1).Find(What:=scannedCode, LookIn:=xlValues, LookAt:=xlWhole)
    
    If Not foundProduct Is Nothing Then
        ' Product found, retrieve information
        Dim productName As String
        Dim productPrice As Double
        
        ' Retrieve product name and price from adjacent cells
        productName = foundProduct.Offset(0, 1).Value
        productPrice = foundProduct.Offset(0, 2).Value
        
        ' Update labels to display product information
        ProductNameLabel.Caption = "Product Name: " & productName
        ProductPriceLabel.Caption = "Price: $" & Format(productPrice, "0.00")
        
        ' Populate the initial TextBox with the scanned barcode
        If BarcodeTextBox.Value = "" Then
            BarcodeTextBox.Value = scannedCode
        Else
            ' Add a new TextBox below BarcodeTextBox for continuous scanning
            AddNewBarcodeTextBox scannedCode, productName, productPrice
            SendKeys "{TAB}", False
        End If
    Else
        ' Product not found, clear labels
        ProductNameLabel.Caption = ""
        ProductPriceLabel.Caption = ""
    End If
End Sub

Private Sub AddNewBarcodeTextBox(ByVal scannedCode As String, ByVal productName As String, ByVal productPrice As Double)
    ' Add a new TextBox and Label below BarcodeTextBox
    Dim newTextBox As MSForms.TextBox
    Dim newLabelName As MSForms.Label
    Dim newLabelPrice As MSForms.Label
    Set newTextBox = Me.Controls.Add("Forms.TextBox.1")
    Set newLabelName = Me.Controls.Add("Forms.Label.1")
    Set newLabelPrice = Me.Controls.Add("Forms.Label.1")
    count = count + 1
    With newTextBox
        .Top = BarcodeTextBox.Top + (count * (BarcodeTextBox.Height + 5)) ' Position below the previous TextBox
        .Left = BarcodeTextBox.Left
        .Width = BarcodeTextBox.Width
        .Height = BarcodeTextBox.Height
        .Name = "NewBarcodeTextBox" & count
        .TabStop = True
        .SetFocus
    End With
    With newLabelName
        .Top = newTextBox.Top
        .Left = newTextBox.Left + newTextBox.Width + 5
        .Width = 100 ' Adjust label width as needed
        .Height = newTextBox.Height
        .Caption = "Product Name: " & productName
    End With
    
    With newLabelPrice
        .Top = newLabelName.Top
        .Left = newLabelName.Left + newTextBox.Width + 5
        .Width = 100 ' Adjust label width as needed
        .Height = newLabelName.Height
        .Caption = "Price: $" & Format(productPrice, "0.00")
    End With
    
    ' Increase UserForm height to accommodate new TextBox and Label
    Me.Height = Me.Height + newTextBox.Height + 5
    
    ' Center the UserForm on the screen
    CenterUserForm
End Sub

Private Sub CenterUserForm()
    ' Center the UserForm on the screen
    Me.Top = (Application.Height - Me.Height) / 2
    Me.Left = (Application.Width - Me.Width) / 2
End Sub

Below is an image of the Userform name
enter image description here

Let me know if there is any more information I should provide. Thank you in advanced!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật