I tried to tackle this problem before but I feel like I have a better idea on how to do it now.
I have a bunch of barcodes that when scanned end with the following
Code:
10 LF (linefeed)
13 CR (carriage return)
10 LF
13 CR
32 Space
10 LF
13 CR
13 CR
Since Access likes to treat LF and CR like pressing the enter key I don't want it to automatically go to the next control on the form and press enter (since the next control is a button that updates records).
I was previously using an invisible control to handle that but it was not working the way I wanted.
The way I want it to work is that the user (and only the user) needs to press enter to move to the next control or click the button/next control. So I want to essentially nullify these LF's and CR's.
There are already thousands of these barcodes made up so I cannot change the barcode and they do not plan to.
There are 7 LF/CR's (I don't know why there is a space) so my idea is to on keypress get the ascii of the key as an int and use a select statement to count how many LF/CR's have been typed.
This part of the code seems to work but then it pushes the actual text up inside the textbox so I wanted to remove the LF/CR's.
I was thinking to use the code below but it just wants to delete some of the actual text instead of deleting the LF/CR.
Code:
Private Sub DhrScanTxt_KeyPress(KeyAscii As Integer)
Dim strCharacter As String
strCharacter = Form_Main.DhrScanTxt.Text
KeyPressed = KeyAscii
Debug.Print KeyAscii
If Not (IsNull(strCharacter) Or (strCharacter = "")) Then
Select Case KeyAscii
Case 10, 13
iCount = iCount + 1
Debug.Print iCount
Form_Main.DhrScanTxt.Text = Replace(Form_Main.DhrScanTxt.Text, 0, (Len(Form_Main.DhrScanTxt.Text) - 1)) 'I tried using mid first.
If iCount = 8 Then
'Me.StepCompleteBttn.SetFocus
End If
End Select
End If
End Sub
Basically I was gonna have it count the LF/CR's so that it ignores the 7 from the barcode. That way when the user presses it, it will be the 8th time it will move the focus to the next control.
Any advice on how to accomplish this?