My Form has 6 Text Box fields and just 1 of them need to set the correct value format.
I just want to set it to make the prefix value to be as alphabet otherwise it will prompt message Invalid.
I’ve try to use below code, but it just to allow first character to be as alphabet can’t vary, and not allow to put dash (-).
I'm glad if someone can help me on this...Thanks !!
I just want to set it to make the prefix value to be as alphabet otherwise it will prompt message Invalid.
I’ve try to use below code, but it just to allow first character to be as alphabet can’t vary, and not allow to put dash (-).
Code:
Private Sub SerialNumber_KeyPress(KeyAscii As Integer)
On Error GoTo SerialNumber_KeyPress_Error
If KeyAscii <> 8 Then 'Checks if Backspace key was pressed
Me.SerialNumber.SelStart = Len(Me.SerialNumber.Text) 'This makes sure that characters
'are entered in order (A00000)
If Len(Me.SerialNumber.Text) < 1 Then
If (KeyAscii < 97 Or KeyAscii > 122) And _
(KeyAscii < 65 Or KeyAscii > 90) Then 'Ensures that First
KeyAscii = 0 'Character is A through Z
Else
If (KeyAscii >= 97 And KeyAscii <= 122) Then
KeyAscii = KeyAscii - 32 ' Capitalize the first charater
End If
End If
Else ' If Keypress is not the First Character and only allows numbers
If (KeyAscii >= 48 And KeyAscii <= 57) Then 'Only allows numbers after
KeyAscii = KeyAscii 'First Letter
Else
KeyAscii = 0
End If
End If
End If
On Error GoTo 0
Exit Sub
SerialNumber_KeyPress_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SerialNumber_KeyPress of " & Me.Name
End Sub