There is no lostfocus event for textboxes in VBA.
When you double_click a control, the Editor will automatically insert a default event. While the cursor is inside this event, you can choose from a list of available events in the upper right dropdown. (You can also choose the control from the left dropdown,)
Private Sub txtBarcode_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim WS As Worksheet
Dim NextRow As Long
Select Case Len(Me.txtBarcode.Text)
Case 12
Set WS = Worksheets("Barcode_Data")
With WS
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
Range("A" & NextRow) = txtseqnum.Value
Range("B" & NextRow) = txtBarcode.Value
End With
txtseqnum.Value = ""
txtBarcode.Value = ""
Case Else
MsgBox "Barcode incorrect", vbInformation, "Barcode scan"
Me.txtBarcode.SetFocus
Cancel = True
End Select
End Sub
Private Sub txtseqnum_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(Me.txtseqnum) <> 7 Then
MsgBox "Seqyunce number incorrect", vbInformation, "Sequence number"
Me.txtseqnum.SetFocus
Cancel = True
End If
End Sub
Bookmarks