I have an access database. I want to bring up a form with a textbox then have a user scan a barcode into that textbox (15 to 20 characters). Scanning the code into the textbox works great with my USB HID scanner, but once the code is scanned access just sits there. The OnChange event seems like the correct direction. Here is my sample code.
Private Sub Text0_Change()
Debug.Print Me.Text0.Value
Debug.Print Len(Me.Text0.Value)
End Sub
After I scan the barcode, this is the output.
00000000000000000
17
00000000000000000
17
00000000000000000
17
.
.
.
<repeated a total of 17 times>
Am I assuming correctly that OnCurrent is triggered for each character in the code? Using this method I'd have to write code that would ignore all events except for one. Which event should I capture? Will the first change event always hold the entire code? It just sounds like a lot of slop with a huge margin of error.
My goal is to run some code on the scanned barcode without any further user input once the code is scanned (i.e. no requirement for the user to hit enter or a button after scanning the code). Is there something better then OnChange for this function? Is my methodology all wrong?
Thanks in advance for the help.
You could, indeed, use the On Change event. My implementation would vary on how exactly your scanner works. If your scanner just enters a fixed number of lines after scanning a barcode, you could count the number of lines to see if it's finished in your On Change event, and do something if it has.
An alternative is setting the Form.Timer
property in the On Change event to a small number, and then set the timer to 0 and do your actual work in the forms On Timer event. That way you don't have to detect the fact that the whole barcode is scanned, it will just trigger once after changing it's content, and only once (as long as the Form.Timer
number is large enough).
Another alternative are the before and after update event, but they require the user to leave the textbox.