473,396 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Check that field meets set criteria

2
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
Feb 10 '17 #1

✓ answered by PhilOfWalton

OK, you only need a minor modification
Create your query and have a column LicenceOK:CheckLicence(LicenceNo)

Then modify the code to
Expand|Select|Wrap|Line Numbers
  1. Function CheckLicence(LicenceNo as string) as Boolean
  2.     Dim i as Integer
  3.  
  4.     For i = 1 to 5
  5.         If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
  6.             Exit Function
  7.        End If
  8.     Next i
  9.  
  10.  For i = 6 to 11
  11.         If Asc(Mid(LicenceNo, i,1)) < 48 OR Asc(Mid(LicenceNo, i,1)) > 57 then
  12.             Exit Function
  13.        End If
  14.     Next i
  15.  
  16.     For i = 12 to 13
  17.         If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
  18.             Exit Function
  19.        End If
  20.     Next i
  21.  
  22. CheckLicence = True
  23.  
  24. End Function
  25.  
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
Frinavale
9,735 Expert Mod 8TB
Have you considered using Regular Expressions?
Feb 10 '17 #2
PhilOfWalton
1,430 Expert 1GB
One way is to check the Ascii value of each letter / number

Air Code
Expand|Select|Wrap|Line Numbers
  1. Dub CheckLicence(LicenceNo as string)
  2.     Dim i as Integer
  3.  
  4.     For i = 1 to 5
  5.         If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
  6.             Msgbox "Initial letters are wrong!, VBCritical
  7.             Exit Sub
  8.        End If
  9.     Next i
  10.  
  11.  For i = 6 to 11
  12.         If Asc(Mid(LicenceNo, i,1)) < 48 OR Asc(Mid(LicenceNo, i,1)) > 57 then
  13.             Msgbox "Initial numbers are wrong!, VBCritical
  14.             Exit Sub
  15.        End If
  16.     Next i
  17.  
  18.  
  19.     For i = 12 to 13
  20.         If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
  21.             Msgbox "Final letters are wrong!, VBCritical
  22.             Exit Sub
  23.        End If
  24.     Next i
  25.  
  26.  
Phil
Feb 10 '17 #3
knee78
2
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.
Feb 13 '17 #4
PhilOfWalton
1,430 Expert 1GB
OK, you only need a minor modification
Create your query and have a column LicenceOK:CheckLicence(LicenceNo)

Then modify the code to
Expand|Select|Wrap|Line Numbers
  1. Function CheckLicence(LicenceNo as string) as Boolean
  2.     Dim i as Integer
  3.  
  4.     For i = 1 to 5
  5.         If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
  6.             Exit Function
  7.        End If
  8.     Next i
  9.  
  10.  For i = 6 to 11
  11.         If Asc(Mid(LicenceNo, i,1)) < 48 OR Asc(Mid(LicenceNo, i,1)) > 57 then
  12.             Exit Function
  13.        End If
  14.     Next i
  15.  
  16.     For i = 12 to 13
  17.         If Asc(Mid(LicenceNo, i,1)) < 65 OR Asc(Mid(LicenceNo, i,1)) > 123 then
  18.             Exit Function
  19.        End If
  20.     Next i
  21.  
  22. CheckLicence = True
  23.  
  24. End Function
  25.  
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
Feb 13 '17 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
1
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.
2
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...
6
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...
3
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...
4
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...
2
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...
9
LeighW
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...
1
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? ...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.