eddyrcabrera79
Member
I have a text box where you can only enter 12 alphanumerical characters. please see the below code.
If by any change the user doesn't input the 12 characters and go to a different textbox, I would like the user to receive a message saying "12 Characters required". I would like for the user not to be able to leave the textbox unless completed.
If by any change the user doesn't input the 12 characters and go to a different textbox, I would like the user to receive a message saying "12 Characters required". I would like for the user not to be able to leave the textbox unless completed.
Code:
'Alphanumerical
Public Function AlphaNumericOnly(strSource As String) As String
Dim i As Integer
Dim strResult As String
For i = 1 To Len(strSource)
Select Case Asc(Mid(strSource, i, 1))
Case 48 To 57, 65 To 90, 97 To 122: 'include 32 if you want to include space
strResult = strResult & Mid(strSource, i, 1)
End Select
Next
AlphaNumericOnly = strResult
End Function
'Character limit
Private Sub SerialNumberTextBox_Change()
' limit amount of characters
Me.SerialNumberTextBox.MaxLength = 10
'Characters uppercase
SerialNumberTextBox.Value = UCase(AlphaNumericOnly(SerialNumberTextBox.Value))
End Sub