Form with TextBox = Value strat with characters letter/alphabet

Niel HS

Registered User.
Local time
Today, 10:40
Joined
Apr 4, 2011
Messages
14
Hello,
I've access database with the Form has Text Box field need to validate the value, the users will only allow to input start with prefix characters letter/alphabet then follow by numeric, inversely will not allow.
The digit number of characters letter/alphabet may vary as well as the numeric and can be able to put dash in the middle.
e.g ABCD12-1234, KTR908B-1234, EMK5-17892

I'm very happy if someone can help me on this...

Thanks,
Niel
 
Welcome to the forum.

You could use the principals demonstrated in this article to test for leading alphabetic characters.
 
Thanks John, but I’ve no idea how to use it under Function code..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 (-).

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
 
Last edited:
Hello Guys,
Anyone can help on this, i'm glad to wait for the good solution.

Thanks,
Niel
 

Users who are viewing this thread

Back
Top Bottom