Alphanumeric validation.

Matticus

New member
Local time
Today, 09:33
Joined
Nov 21, 2013
Messages
4
Hello, what would I need to enter into the validation rule to change the field to alphanumeric only? Please help :)
 
I need a little more info to answer. What data is being stored in the field?
 
Forenames are being entered, I want to stop the user of the database entering punctuation. :)
 
Put this code in your before update event for your forename control

Code:
Private Sub Text0_BeforeUpdate(Cancel As Integer)
Dim i As Integer
    For i = 1 To Len(Text0.Text)
        If Asc(UCase(Mid(Text0.Text, i, 1))) < 65 Or Asc(UCase(Mid(Text0.Text, i, 1))) > 90 Then
            MsgBox "only alpha characters allowed"
            Cancel = True
            Exit Sub
        End If
    Next i
    
End Sub

It allows A-Z characters in upper or lower case - if you want to also include numbers you will need to modify the if statement slightly to allow for these as well.

For a full list of ascii characters - see here

http://www.asciitable.com/
 

Users who are viewing this thread

Back
Top Bottom