Validating car reg plate

boyblundell

New member
Local time
Today, 00:57
Joined
May 4, 2004
Messages
5
I am looking for a very clever and quick person to hopefully right me a code that will work to validate a british reg plate for a car. It only has to be for the new style of AB12CDE, however i ahve found some rules which is making it impossible. I can validate if each character has its own field. but i want it in one field.
Rules
a=cannot have characters IJQTUZ
B=Cannot ahve IQZ
CDE=cannot have I or q

If anyone could help it would be excellent.
 
Put this in a module:

Code:
Public Function IsRegistration(strReg As String) As Boolean

    On Error GoTo Err_IsRegistration
    
    Dim strPos As String
    Dim intCounter As Integer
    
    If Len(strReg) <> 7 Then Exit Function
    
    strReg = StrConv(strReg, vbUpperCase)
    
    For intCounter = 1 To 7
        strPos = Mid(strReg, intCounter, 1)
        Select Case intCounter
            Case Is = 1, 2, 5, 6, 7
                If Asc(strPos) < 65 Or Asc(strPos) > 90 Then Exit Function
                If intCounter = 1 Then
                    Select Case strPos
                        Case Is = "I", "J", "Q", "T", "U", "Z"
                            Exit Function
                    End Select
                End If
                If intCounter = 2 Then
                    Select Case strPos
                        Case Is = "I", "Q", "Z"
                            Exit Function
                    End Select
                End If
                If intCounter > 4 Then
                    Select Case strPos
                        Case Is = "I", "Q"
                            Exit Function
                    End Select
                End If
            Case Is = 3, 4
                If Not IsNumeric(Mid(strReg, intCounter, 1)) Then Exit Function
        End Select
    Next intCounter
    
    IsRegistration = True
Exit_IsRegistration:
    strPos = vbNullString
    Exit Function
    
Err_IsRegistration:
    IsRegistration = False
    Resume Exit_IsRegistration

End Function


Call it like so (changing txtRegistration to the name of the textbox):

Code:
If IsRegistration(Me.txtRegistration) = True Then
    MsgBox "It's allowed."
Else
    MsgBox "That's not right!"
End If
 
Last edited:
Help again

Where do i paste the bottom bit of caode. And i want to validate the field in the table if possible. I have pasted the bottom bit of code into the validation rule in both the table and form and have had invalid syntax in the code. If possible could i send the project over for you to ha e a look at.
 
You can't use a custom function in a table's Validation Rule - it will have to be in the form that you bind to the table/query.
 

Attachments

Case Select error

Case Is = 3, 4 this part is not working
its part of this piece of code.
Case Is = 3, 4
If Not IsNumeric(Mid(strReg, intCounter, 1)) Then Exit Function
End Select

please help. This is the error i am getting.
Case without Select Case


A Case statement must occur within a Select Case...End Select Block. This error has the following cause and solution:

A Case statement can't be matched with a preceding Select Case statement.
Check other control structures within the Select Case...Case structure and verify that they are correctly matched. For example, an If without a matching End If inside the Select Case...End Select structure generates this error.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).
 
I'd missed out a line in the code above - recopy it now.
 
Yes. Or the attachement (I'd corrected the error in that already).
 
Very Nice looking Forum!!! I wonder if it will make the history books?
 
validate reg plate for normal vehicles aswell??

hi SJ McAbney, ur knowledge of access is quite remarkable. I was wondering if there is a way to validate a reg plate for both standard (old style) reg numbers, e.g. R323SSD and new ones: JT54AER ?
I would really be interested if there is. thanxs
 
What's the logic for the old style? Me not being a driver or being interested in cars, etc. :)
 
hi, thanks for ur reply. i need it for a used car sales database. when an incorrent entry is input - need error message. so needs to accomodate types such as:
L45ASD
R543LDS
FT54KES

thanks
 
Okay, but I need to understand the rules. i.e. boyblundell's original post
 

Users who are viewing this thread

Back
Top Bottom