0

I have simple form which i am planning to use on audit the sorting station at my work. Its pretty simple and looks like this:

.

The Problem: I'm using a handheld scanner (Symbol LI4278) to scan bar codes of every SKU contained in a certain bulk. The procedure is simple:

  1. Scan the bulk Code (Label: Etiqueta de Bulto)
  2. Then, the focus drops on SKU text Label
  3. Scan every SKU Barcode
  4. Send information to an access data base.

My problem lies in that after i scan a SKU Barcode, focus does not return to text label (T4) in order to keep scanning (SKU TEXT LABEL = T4), unless i hit TAB once. I need this to be automatic, and setfocus property is not working.

Here's my code:

Private Sub txtSKU_Change()

            Application.EnableEvents = False
            txtBulto.Locked = True

            If Len(Me.txtSKU.Value) = 13 Then

                Me.L1.ColumnCount = 3
                Me.L1.AddItem Me.txtBulto.Value
                Me.L1.List(L1.ListCount - 1, 1) = Me.txtSKU.Value
                Me.L1.List(L1.ListCount - 1, 2) = Me.txtAuditor2.Value
                End If

              txtSKU.SetFocus  
            Application.EnableEvents = True
     End Sub

I would really appreciate your help on this. I need this application to work perfect for operation purposes and reduce mistakes.

Regards

enter image description here

6
  • 1
    I'm pretty sure you can't set focus to a label. Labels are not meant to be interactive. Try using a Text Box instead. Commented May 16, 2018 at 17:07
  • FWIW SkuCodeBox would be INFINITELY clearer than T4 or T3 or L1 for a name. Use meaningful names, thank yourself later. Commented May 16, 2018 at 17:28
  • @ashleedawg My bad, i'm trying to set the focus on TextBox, not a Label. Commented May 16, 2018 at 18:53
  • @MathieuGuindon edited. Commented May 16, 2018 at 18:53
  • With txtSKU (the big textbox where you suppose to scan many items?), is the MultiLine property set to True and EnterKeyBehavior set to True? Most scanners inserts a tab/enter on each successful scan Commented May 18, 2018 at 5:57

3 Answers 3

1

Assuming the barcode scanner automatically appends an Enter on each successfull scan, you just need to trap that Enter at KeyDown event and replace with KeyCode 0.

Try comment your txtSKU_Change Sub and append below to test:

Private Sub txtSKU_Change()
    Dim sValue As String
    With Me.txtSKU
        sValue = WorksheetFunction.Trim(.Value)
        If Len(sValue) = 13 Then
            With Me.L1
                .AddItem Me.txtBulto.Value
                .List(.ListCount - 1, 1) = sValue
                .List(.ListCount - 1, 2) = Me.txtAuditor2.Value
            End With
            .Value = vbNullString
        End If
    End With
End Sub

Private Sub txtSKU_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then KeyCode = 0 ' Rejects Enter Key
End Sub

Sign up to request clarification or add additional context in comments.

1 Comment

@HectorNunez please do mark this as answer to close this post.
0

Please use code similar to this:

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, _
            ByVal X As Single, ByVal Y As Single)

   If UserForm1.ActiveControl.Name = "List1" Then
   UserForm1.TextBox1.SetFocus
   End If

End Sub

1 Comment

Welcome to SO! When you reply to a question with code, try to explain it a little bit.
0

First of all, set the Cycle property of your form to 2 - fmCycleCurrentForm. Then, use Application.SendKeys to navigate to your desired object.

Below is an example code where I scan a QR code in the Serial_number textbox and set the focus back to the Serial_number textbox using the code provided:

Private Sub cmd_add_color_Click()
    Call addColor
    cmb_color.SetFocus
    Application.SendKeys "{TAB}"       ' Getting setfocus back to the serial textbox
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.