Check if barcode contains 2 or 6 digits - vba userform

Ricardasr25

New Member
Joined
Dec 29, 2013
Messages
21
Hi Guys,

I have a code in userform which I use to transfer data from one sheet to another when the barcode is scanned into the userform textbox(txtOrder), the barcode with order number contains 6 digits .

I have another textbox in userform called txtOperator, this textbox is also filled when scanning the barcode but now it contains only two letters.

So my issue is if not correct textbox is selected by operators it my cause barcode to scan into wrong textbox, lets say that order number will be scanned into operators textbox(txtOperator) and off course it could be in opposite way.

This is what i would like to achieve:

Barcode scanning issue Please help
http://www.excelforum.com/excel-prog...-scanning.html

1.txtOperator textbox - Check if barcode contains 2 letters and if it is true leave it in a txtOperator textbox, but if it's more than 2 scan into txtOrder
2.txtOrder textbox - check if barcode contains more than 2 letters and if it is true leave it in txtOrder textbox, but if it's equals 2 letters scan into txtOperator

Below is my code and i also attached the file.

Thanks in advance for your help.

Code:
[/COLOR]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Private Sub txtOrder_Change()

If Len(UserForm1.txtOrder) = 6 Then
UserForm1.TextBox1.Visible = False
UserForm1.TextBox1.Visible = True

'Application.ScreenUpdating = False
Dim strSearch As String
Dim rngFound As Range, firstAddress As String
Dim lngCounter As Long
Dim strAddress As String
Dim lngHelp As Long
Dim arrCol As Variant
Dim Ctrl As Control
Dim A As Long, B As Long
Dim MyName As String, myRange As Range
Dim found As Range
Dim WSdb As Worksheet
Dim C As Long
Dim NextRow As Long
Dim aCol As Long
Dim aRec As Long
Dim ans As String
 For C = 1 To 22
Dim x As Integer
For x = 1 To 22

Next x
 MyName = UserForm1.txtOrder.Text
   Set myRange = ThisWorkbook.Sheets("Update").Range("Update")
   Set found = myRange.Find(MyName, LookIn:=xlValues, LookAt:=xlWhole)
   If Not found Is Nothing Then
For Each Ctrl In UserForm1.Controls
        If Left(Ctrl.Name, 3) = "lbl" Then
            Ctrl.Caption = ""
        End If
        
    Next

    With ThisWorkbook.Sheets("Update")
        With .Range("A:A")
            strSearch = UserForm1.txtOrder.Text
            Set rngFound = .Find(strSearch, LookIn:=xlValues, LookAt:=xlWhole)
            If Not rngFound Is Nothing Then
                firstAddress = rngFound.Address
                Do
                    If lngCounter >= 22 Then Exit Sub
                    lngCounter = lngCounter + 1
                    UserForm1.Controls("lblProd" & lngCounter).Caption = rngFound(, 1)
                    UserForm1.Controls("lblDesc" & lngCounter).Caption = rngFound.Offset(, 1)
                             
                             Set rngFound = .FindNext(rngFound)
                       Loop While Not rngFound Is Nothing And rngFound.Address <> firstAddress
                 

If UserForm1.Controls("lblDesc" & C).Caption <> "" Then
    Set WSdb = Worksheets("Data Collection")
    With WSdb
            'Database next empty row.
            NextRow = .Cells(.Rows.Count, "C").End(xlUp).Row + 1

            'Write to worksheet.
            .Cells(NextRow, 1) = UserForm1.Controls("txtOperator")
             .Cells(NextRow, 2) = UserForm1.Controls("txtTime")
            .Cells(NextRow, 3) = UserForm1.Controls("lblProd" & C).Caption
            .Cells(NextRow, 4) = UserForm1.Controls("lblDesc" & C).Caption
              txtTime.Value = Format(Time, "Long Time")
                                  'Reset the next empty row.
            NextRow = .Cells(.Rows.Count, "C").End(xlUp).Row + 1
        End With
       End If
    lngCounter = 0
UserForm1.txtOrder.SetFocus
    UserForm1.txtOrder.SelStart = 0
    UserForm1.txtOrder.SelLength = Len(UserForm1.txtOrder.Text)
    
End If
End With
End With
End If
Next
End If
End Sub</code>

 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I think you might mean

Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">If Len(UserForm1.txtOrder) = 6 Then
UserForm1.TextBox1.Visible = False
UserForm1.TextBox1.Visible = True

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">If Len(UserForm1.txtOrder) = 6 Then
UserForm1.TextBox1.Visible = False
Else
UserForm1.TextBox1.Visible = True
Ends If</code></code>

soemthing similar may work if you scan to a variable and then determine the length of the variable to trigger where to place the item

I have a passing interest in barcodes but not done anything with them
 
Upvote 0
Hi mole999,

Thanks for reply, but this is not what exactly need.

This is what i would like to achieve:

The main issue is when i use the "Len" it executes the code when the first two letters or digits appear in textbox, maybe there is a way to pause the code for second or half second (just to give some time to scan fully the barcode)?

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">If Len(UserForm1.txtOrder) = 2 Then
copy what is in this textbox and paste into txtOperator and then clear the txtOrder,
but If Len(UserForm1.txtOrder) = 6 Then
proceed with the full code and also

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">
If Len(UserForm1.txtOperator) = 2 Then
leave as it is and then select the txtOperator
but
if Len(userform1.txtOperator) = 6
copy what is txtOperator into txtOrder and then clear txtOperator</code>
</code></pre>
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,265
Members
449,149
Latest member
mwdbActuary

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