Hello Everyone,
I'm working on a simple GUI to input serial numbers. I have created a textbox in a userform to allow a input of a serial number using a hand scanner. The scanner will read serial number and submit an Enter command upon completion of input. Using the Enter command allows the user to progress within the userform into the next textbox.
I have setup some simple conditions to validate the entry within the TextBox_AfterUpdate sub. In the event the input does not meet these conditions, a msgbox informs the user to reenter the serial number. After acknowledging of the msgbox prompt, the sub returns focus to the textbox and highlights the incorrect serial number. Routine should then exit the AfterUpdate sub. When executing the userform all appears to function as intended and the incorrect entry is indeed highlighted if validation conditions are not met.
My thought process was to allow the user to correct their entry with the hand scanner which upon completion of the new entry, would trigger the TextBox_AfterUpdate sub again and begin validation of the new entry. This was the intent, however, the userform just hangs after the new entry and it doesn't appear the AfterUpdate sub is being called even tho the input has changed and Enter command issued from scanner. When using debug mode the routine does indeed hang after exiting the AfterUpdate sub, yet never highlights the incorrect input.
Any thoughts on the way im approaching this problem? Am I using the AfterUpdate sub incorrectly or simple not executing the logic correctly after the textbox reentry event? Any advice would be appreciated.
I'm working on a simple GUI to input serial numbers. I have created a textbox in a userform to allow a input of a serial number using a hand scanner. The scanner will read serial number and submit an Enter command upon completion of input. Using the Enter command allows the user to progress within the userform into the next textbox.
I have setup some simple conditions to validate the entry within the TextBox_AfterUpdate sub. In the event the input does not meet these conditions, a msgbox informs the user to reenter the serial number. After acknowledging of the msgbox prompt, the sub returns focus to the textbox and highlights the incorrect serial number. Routine should then exit the AfterUpdate sub. When executing the userform all appears to function as intended and the incorrect entry is indeed highlighted if validation conditions are not met.
My thought process was to allow the user to correct their entry with the hand scanner which upon completion of the new entry, would trigger the TextBox_AfterUpdate sub again and begin validation of the new entry. This was the intent, however, the userform just hangs after the new entry and it doesn't appear the AfterUpdate sub is being called even tho the input has changed and Enter command issued from scanner. When using debug mode the routine does indeed hang after exiting the AfterUpdate sub, yet never highlights the incorrect input.
Any thoughts on the way im approaching this problem? Am I using the AfterUpdate sub incorrectly or simple not executing the logic correctly after the textbox reentry event? Any advice would be appreciated.
Code:
Private Sub SerialIn_AfterUpdate()
'Begin processing user input.
If Len(SerialIn.Value) = 19 Then 'validate serial number length
SerialInTime.Caption = Now 'record date and time
SerialOut.SetFocus 'set focus on next textbox
Else
Dim Msg As String 'set error message
Msg = "Opps, something went wrong! Serial number was incorrect." _
& vbNewLine & vbNewLine & "Rescan module serial number."
msgbox Msg, vbCritical, "Warning"
SerialIn.SetFocus 'return focus to textbox
SerialIn.SelStart = 0 'highlight user text
SerialIn.SelLength = 99
End If
End Sub