By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,704 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,704 IT Pros & Developers. It's quick & easy.

Prevent user keying by keyboard and can only input by barcode scanner

P: 1

I intend to use barcode for input and prevent user to modify the barcode they scan, user are not allow to input the barcode number by keyboard.

Please advise how to do this.


Jul 16 '08 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 2.5K+
P: 2,545
Hi. Most barcode scanners for PCs use the keyboard connection, and the scan behaves just as if you had typed the value. I can see no way to prevent users either keying the barcode directly, or altering it once a barcode has been scanned.

Even if you could implement such a facility, you would also be stopping users from manually keying barcodes if the scan fails for some reason.

Jul 20 '08 #2

Expert 2.5K+
P: 3,532
Stewart raises a valid point, but if you absolutely must do this , this code will do the job:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtBarCode_KeyDown(KeyCode As Integer, Shift As Integer)
  2.   KeyCode = 0
  3. End Sub
Or you could simply set the textbox's Locked Property to Yes. I don't have a scanner, so I can't really test this, but both methods appear to handle your situation.

Welcome to Bytes!

Linq ;0)>
Jul 20 '08 #3

Expert 100+
P: 1,134
I have done both of those for the purpose of obtaining part labels.
Stop the user entering maually similar to missinglig's code.
Stopped production getting labels because the scanner failed.

We finished up enabling users to manually enter part numbers, but we deliberately made it more difficult to obtain them that way than by using the scanner. It worked :)

Actually, on second thoughts, I think I may have had to wrap the barcoded number up in special characters and check the entered number for the presence of those characters before allowing the entry.
Jul 21 '08 #4

P: 1
This is how I solved it:

Expand|Select|Wrap|Line Numbers
  1. Public FirstInput As Date
  3. Private Sub Text0_GotFocus()
  4. FirstInput = Empty
  5. End Sub
  8. Private Sub Text0_KeyUp(KeyCode As Integer, Shift As Integer)
  9. Dim TimeDiff As Integer
  10. 'Procedure uses first keystroke to start timing, and every subsequent keystroke compares
  11. 'to the first, and if more than 1 second has elapsed, warns user to use the scanner and resets field.
  12. 'tabbing away or back to the field resets the timer. Tabbing off the field or hitting enter to move to
  13. 'the next field will not be counted as keystrokes.
  15. If KeyCode <> 9 And KeyCode <> 13 Then
  16. If FirstInput = Empty Then
  17. FirstInput = Now()
  18. Else
  19. TimeDiff = DateDiff("s", FirstInput, Now())
  20. End If
  22. If TimeDiff > 1 Then
  23. MsgBox ("Please scan in using the attached scanner")
  24. Text0.Text = Empty
  25. FirstInput = Empty
  26. End If
  28. End If
  30. End Sub
  32. Private Sub Text0_LostFocus()
  33. FirstInput = Empty
  34. End Sub
Sep 21 '16 #5

Expert 5K+
P: 8,692
You can actually disable all User Input via the Mouse and Keyboard then re-enable it via the API, but this may be somewhat extreme.
Sep 21 '16 #6

Post your reply

Sign in to post your reply or Sign up for a free account.