Hi,
I need to check though a huge amount of driving licence numbers and pick out ones that do not confirm to the predefined layout of a driving licence.
For example I might want the first 5 characters to be a letter followed by 6 numbers and then 2 letters. I want to be able to identify anything that does not follow this structure. eg :-
Driving licence Number Correct format ?
Jones220578GG Y
Jones24ddwe96 N
OK, you only need a minor modification
Create your query and have a column LicenceOK:CheckLicence(LicenceNo)
Then modify the code to -
Function CheckLicence(LicenceNo as string) as Boolean
-
Dim i as Integer
-
-
For i = 1 to 5
-
If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
-
Exit Function
-
End If
-
Next i
-
-
For i = 6 to 11
-
If Asc(Mid(LicenceNo, i,1)) < 48 OR Asc(Mid(LicenceNo, i,1)) > 57 then
-
Exit Function
-
End If
-
Next i
-
-
For i = 12 to 13
-
If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
-
Exit Function
-
End If
-
Next i
-
-
CheckLicence = True
-
-
End Function
-
So what happens is that if any of the tests fail, CheckLicence returns 0 (False). If all the tests pass, we set CheckLicence to True.
Phil
4 1003
One way is to check the Ascii value of each letter / number
Air Code -
Dub CheckLicence(LicenceNo as string)
-
Dim i as Integer
-
-
For i = 1 to 5
-
If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
-
Msgbox "Initial letters are wrong!, VBCritical
-
Exit Sub
-
End If
-
Next i
-
-
For i = 6 to 11
-
If Asc(Mid(LicenceNo, i,1)) < 48 OR Asc(Mid(LicenceNo, i,1)) > 57 then
-
Msgbox "Initial numbers are wrong!, VBCritical
-
Exit Sub
-
End If
-
Next i
-
-
-
For i = 12 to 13
-
If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
-
Msgbox "Final letters are wrong!, VBCritical
-
Exit Sub
-
End If
-
Next i
-
-
Phil
Hi Sorry I could get this to work. I needed to have a query really. So the field in the query would be the LicenceNo and then a Y/N for whether it conforms to the licence layout.
OK, you only need a minor modification
Create your query and have a column LicenceOK:CheckLicence(LicenceNo)
Then modify the code to -
Function CheckLicence(LicenceNo as string) as Boolean
-
Dim i as Integer
-
-
For i = 1 to 5
-
If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
-
Exit Function
-
End If
-
Next i
-
-
For i = 6 to 11
-
If Asc(Mid(LicenceNo, i,1)) < 48 OR Asc(Mid(LicenceNo, i,1)) > 57 then
-
Exit Function
-
End If
-
Next i
-
-
For i = 12 to 13
-
If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
-
Exit Function
-
End If
-
Next i
-
-
CheckLicence = True
-
-
End Function
-
So what happens is that if any of the tests fail, CheckLicence returns 0 (False). If all the tests pass, we set CheckLicence to True.
Phil
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MLH |
last post by:
I have an A97 query (qryVehiclesNowners2) that has a table
field in it named . Depending on the selections made
in a number of criteria choices on a form, a field on the form
will have string...
|
by: sleepyant |
last post by:
Hi, how can I check the field data type of a column in a Dataset table? Like
whether it is a DateTime, a Binary or Character.
Please help. Thanks.
|
by: sconard |
last post by:
I cannot seem to refer to a derived field in criteria. Better phrased: I cannot refer to a derived field in the where clause of the query. The following does not use the value from the derived...
|
by: tmoon3 |
last post by:
Hello All,
I have a report where it lista employees that need to have an eval done in the next 30 days.
If the employee has a 3 month, 6 month or 12 month eval due in the next 30 days it lists...
|
by: accessbeginerry |
last post by:
I have a form with subforms on it (subforms are designed on tabcontrol and each has separate page)
After user enter information on form and tries to hit "Save" button i would like the access...
|
by: KiwiGenie |
last post by:
I have an image on my report that I want to make visible only when a yes/no field is true. The yes/no field is a hidden text box called txtTried. The code I've been trying to use is:
If Me!txtTried...
|
by: jmaher196 |
last post by:
Hello all!
I have a table that is used to track custoemr visits that contains the following fields: and . field uses the simple mm/dd/yyyy format.
On a form I have created, I would like...
|
by: LeighW |
last post by:
Hi all,
I'd like a cover page that shows which filter criteria have been used when creating the report. If this can't be done/ is very hard to implement then I'll leave it be but I thought it...
|
by: sc5502 |
last post by:
Background:
MS SQL Server 2005
How do check a field for one of two values? I have a field Status in SQL that can a "A" or "I" or "W". I want to check it for a "A" or "I". How can I do that?
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |