Solved

Access 2003 chaeck field to see if it contains a certain pattern

Posted on 2011-03-02
5
280 Views
Last Modified: 2012-05-11
Hi There,

I have a 12 digit field.
I want to be able to check if anywhere in that string it contains 4 consecutive non numeric characters.

eg

1BLT010001   No
2POLK1000    Yes
POL1000        NO
POLK9999      yes

Any Ideas
0
Comment
Question by:EWHTLC
  • 2
  • 2
5 Comments
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
ID: 35017059
you will need a function to do that, place this codes in a regular module
is there a possibility to have more than 4 consecutive Alpha characters


function count4Alpha(str) as boolean
count4Alpha=false
if len(str) < 4 then count4Alpha=False: exit function

dim j, strA as string, xCnt as integer
strA="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for j=1 to len(str)
      if  instr(strA,mid(str,j,1))>0 then
         xCnt=xcnt +1
         if xcnt>=4 then
             count4Alpha=true
             exit function
         end if
         else
         xCnt=0
     end if
next

end function



you can use the function in a query like this

select [field], count4Alpha([field])
fro tableName
0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 250 total points
ID: 35018166
Here is an alternative function that checks for any desired number of alpha characters in a row...


function strNStringAlpha(strInput, nConsecutive) as string
' Checks it there is any string of nConsecutive Alpha characters
' (A-Z, a-z) and returns the string if found
dim nLen as Long
dim n as Long
dim c as String 
dim strResult as string 
dim nAlpha
	nLen = Len(strInput)
	For n = 1 to nLen
		c = Ucase(mid(strInput,n,1))
		If c >="A" and c <= "Z" then
			nAlpha = nAlpha + 1
			strResult = strResult & mid(strInput,n,1)
			if nAlpha = nConsecutive then
				Exit For
			End If
		Else
			nAlpha = 0
			strResult = ""
		End If
	Next N
	strNStringAlpha = strResult
End Function

Open in new window

0
 

Author Comment

by:EWHTLC
ID: 35019666
Both Solutions worked a treat.
2nd one slightly better in that it looked for 4 consecutives.

Brilliant response.

Thanks you for your time

Will split the points.
0
 

Author Closing Comment

by:EWHTLC
ID: 35019676
thanks
0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 35019912
My pleasure.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now