I am scanning a bar code into a textbox called txtBar. After each scan, a record is created and other code is executed. Then the txtBar textbox is cleared and the focus is automatically returned to txtBar. Currently all bar codes are of length 15 and it works perfectly using the On Change event. We are now moving to a 19 character bar code. During the transition period some bar codes of both lengths will have to be scanned. I can no longer use the On Change event with variable length tickets. I am attempting to code it so that when the user presses Enter or some other key, the code will check the length of the bar code and perform the correct code. The following code currently works for scanning 15 character bar codes only:
After switching to 19 character bar codes, it will look something like this:
After I scan a bar code, the cursor tabs to the next textbox on the form. If I then click back on txtBar the above code is executed and does what it is supposed to do, but I don't want the user to have to click back into the textbox.
I would like the focus to stay in txtBar and have the user press Enter or another key to execute the above code. I have tried txtBar.SetFocus in the After Update and On Exit events, but it still tabs to the next field.
Does anyone have any suggestions? Is there another event or another way to get the results I want?
Thanks,
David
Code:
Public Sub txtBar_Change()
If Len(txtBar.Text) = 15 Then
'code for extracting characters from bar code, querying
' database and creating a record
txtBar.Text = " "
End If
End Sub
After switching to 19 character bar codes, it will look something like this:
Code:
Private Sub txtBar_Enter()
If Len(txtBar.Text) = 15 Then
'code for extracting characters from bar code, querying
' database and creating a record
txtBar.Text = " "
If Len(txtBar.Text) = 19 Then
'code for extracting characters from bar code, querying
' database and creating a record
txtBar.Text = " "
End If
End Sub
After I scan a bar code, the cursor tabs to the next textbox on the form. If I then click back on txtBar the above code is executed and does what it is supposed to do, but I don't want the user to have to click back into the textbox.
I would like the focus to stay in txtBar and have the user press Enter or another key to execute the above code. I have tried txtBar.SetFocus in the After Update and On Exit events, but it still tabs to the next field.
Does anyone have any suggestions? Is there another event or another way to get the results I want?
Thanks,
David